Store data from a a loop
1 次查看(过去 30 天)
显示 更早的评论
i am trying to loop through three variables and store the data from each loop:
for rating=1:3
k=rating+1; %start rating
l=10; %end rating
AAADowngrade=zeros(100,l-k+1,rating);
for i=1:100
for j=k:l
AAADowngrade(i,j-k+1,rating) = sum(tHistorical(rating,j:l,i));
end
end
end
However, the code above only stores data from the final rating (rating =3). The first two tables just have zeros in them.
0 个评论
采纳的回答
Walter Roberson
2021-9-15
编辑:Walter Roberson
2021-9-15
maxrating = 3;
AAADowngrade = cell(maxrating,1);
l=10; %end rating
for rating = 1 : maxrating
k = rating+1; %start rating
thisAAADowngrade = zeros(100,l-k+1);
for i=1:100
for j=k:l
thisAAADowngrade(i,j-k+1) = sum(tHistorical(rating,j:l,i));
end
end
AAADowngrade{rating} = thisAAADowngrade;
end
You need a cell array because the arrays are not all the same size.
6 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!