I am trying to assign values to a matrix, which is an array element directly while going through a loop. I am being told however that Subscript indices must either be real positive integers or logicals. But as you can see from the script below, I have read the output for each of the indices before they are actually used and each of them is real positive integer.
The error is produced by the first loop statement fundMoments{1,i}((count-frame(j)+1), meanCol) = mean(fund(count-frame(j)+1:count));- I have run the left side of the line alone with the inputs defined as in the script and it tells me correctly that the value held in the matrix, in the array, is zero. However the complete line does not run.
Any ideas where I am going wrong here?
For some context to the code - I am trying to calculate moving averages (but not only the moving mean, but also the moving std. deviation and so on). The value of frame is the length of the moving time-window being taken into account. funds is a ~2500x8 doubles matrix.
frame = [252 504 756]; % the time frame to be used for moving averages
funds = funds_ROR; %matrix with the returns of all funds
meanCol = 1;
st_devCol = 2;
skewCol = 3;
kurtCol = 4;
%for f = 1:length(frame)
mean = zeros(length(funds) - frame(1), 1);
st_dev = zeros(length(funds) - frame(1), 1);
skew = zeros(length(funds) - frame(1), 1);
kurt = zeros(length(funds) - frame(1), 1);
vectLength = length(mean); % all the four vectors must be of the same length, so we only need use one
fundMoments = {[mean st_dev skew kurt], [mean st_dev skew kurt], [mean st_dev skew kurt], [mean st_dev skew kurt], [mean st_dev skew kurt], [mean st_dev skew kurt], [mean st_dev skew kurt], [mean st_dev skew kurt]};
for i = 1:1:8
fund = funds_ROR(:,i);
for j = 1:length(frame)
for count = frame(j):length(fund)
fund
count
frame_j = frame(j)
meanCol
fund(count-frame(j)+1:count)
fundMoments{1,i}((count-frame(j)+1), meanCol) = mean(fund(count-frame(j)+1:count));
fundMoments{1,i}(count-frame(j)+1, st_devCol) = std(fund(count-frame(j)+1:count));
fundMoments{1,i}(count-frame(j)+1, skewCol) = mean(fund(count-frame(j)+1:count));
fundMoments{1,i}(count-frame(j)+1, kurtCol) = mean(fund(count-frame(j)+1:count));
% fund_kurt = kurtosis(1:1:frame(j));
% date = time_series(frame(j):end);
% figure(frame(j))
% plot(date, fundMoments, date, fund_kurt)
% header = ['Skew and Kurtosis - ', frame, ' moving average'];
% title(header)
% legend('Skew', 'Kurtsosis')
% set(gcf, 'YLim', max(max(fundMoments), max(fund_kurt)))
end
end
end