我是Octave的新手,我正在尝试读取日期时间值的月数,以便用它来做一个等式。问题是每次我尝试读取它时,我都会得到相同的维度错误,我不知道为什么。。。
这是我的代码:
clear
clc
pkg load io
pkg load financial
[num,date] = xlsread('EMA_VR 2019.xlsx','A184:A215');
num=datenum(date);
DataString=datestr(date)
m= month(num,DataString)
结果总是这样:
DataString =
01-Jul-2019
02-Jul-2019
03-Jul-2019
04-Jul-2019
05-Jul-2019
06-Jul-2019
07-Jul-2019
08-Jul-2019
09-Jul-2019
10-Jul-2019
11-Jul-2019
12-Jul-2019
13-Jul-2019
14-Jul-2019
15-Jul-2019
16-Jul-2019
17-Jul-2019
18-Jul-2019
19-Jul-2019
20-Jul-2019
21-Jul-2019
22-Jul-2019
23-Jul-2019
24-Jul-2019
25-Jul-2019
26-Jul-2019
27-Jul-2019
28-Jul-2019
29-Jul-2019
30-Jul-2019
31-Jul-2019
01-Aug-2019
error: horizontal dimensions mismatch (1x1 vs 32x1)
error: called from
month at line 40 column 7
Teste at line 13 column 2
此外,当我试图在某一年或某一天回来时,它总是给我正确的价值,希望有人能帮助我,我将不胜感激。
month
函数只能处理1x1数据。这就是你的错误所说的。由于您的日期向量是32x1,因此您不能像现在这样使用该函数。
但是,您可以使用for循环,并将值存储在向量中:
[num,date] = xlsread('EMA_VR 2019.xlsx','A184:A215');
Month = zeros(size(num)); % Month will have the same dimensions as num
for i=1:length(Month) % Loops through the length of Month
Month(i) = month(num(i)); % Applies the month function to the i-th entry of num
end