Ah okay, I totally understand and I am very sorry and will try tochange it back again. Thank you for noticing me Jan.
Error: Index exceeds the number of array elements (1).
1 次查看(过去 30 天)
显示 更早的评论
%% Omitting NA's from intial dataset
data = rmmissing(Zerocoupondata);
data.SVENY05(12523) = 0.875;
%% Declaring variables:
Time = table2array(data(14:14600,1));% Time variable
Time = datenum(Time); % Declaring time as datenum
Y01 = table2array(data(14:14600,2)); % Bond of 1 year maturity
Y02 = table2array(data(14:14600,3)); % Bond of 2 years maturity
Y03 = table2array(data(14:14600,4)); % Bond of 3 years maturity
Y04 = table2array(data(14:14600,5)); % Bond of 4 years maturity
Y05 = table2array(data(14:14600,6)); % Bond of 5 years maturity
%% Realized Variance
% The variance through the whole sample period
Y05Var = (Y05(2:end) - Y05(1:end-1)).^2;
% Creating a loop to register timeshifts
%%
dates=Time;
g=1;
months = size(Y05Var,1);
years = size(Y05Var,1);
months(1)=month(dates(1));
years(1)=year(dates(1));
temp=1;
%%
for i=1:size(Y05Var,1)
if months(g) == month(dates(i)) & years(g) == year(dates(i));
else
var_monthly(g)=sum((Y05(temp+1:i-1)-Y05(temp:i-2)).^2);
g=g+1;
temp=i;
end
end
I get the error in the line "if months(g) == month(dates(i)) & years(g) == year(dates(i));". I hope you guys can help me. I am new to matlab. Thank you!
采纳的回答
Jan
2021-3-2
You have defined months as a scalar:
months(1) = month(dates(1));
Then months(g) must fail, if g>1.
I cannot guess, what you want to do instead, so it is not possible to suggest a solution. A bold guess:
% Replace: months(1) = month(dates(1)); by
months = month(dates);
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!