Info
此问题已关闭。 请重新打开它进行编辑或回答。
repeating same procedure for two data sets by cell or struct array?
1 次查看(过去 30 天)
显示 更早的评论
I'm struggling to find a way to efficiently repeat the same procedure for two separate data sets. I thought it is something to do with struct or cell arrays, but no idea how to do it. I would truly appreciate your help!
% both data are m by n matrix containing returns of stock prices
rtn1=data1;
rtn2=data2;
% % want to avoid repetition by indexing the data names
% I know it is wrong, but the image of what I would like to do is...
for j=1:2
% operation is done only for the first column of the data
firstRtn=rtn(j)(:,1);
% calculate 1 year average
rollingAve=zeros(length(firstRtn)-251,1);
for i=1:length(rtn(j))-251
rollingAve(i)=average(rtn(j)(i:i+251));
end
figure
plot(rollingAve)
end
0 个评论
回答(1 个)
Walter Roberson
2018-3-30
rtn = {data1; data2};
for j = 1 : length(rtn)
rollingAve = movavg( rtj{j}, 'simple', 251);
figure
plot(rollingAve)
end
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!