필터 지우기
필터 지우기

Store data from a a loop

조회 수: 2 (최근 30일)
RP
RP 2021년 9월 15일
댓글: RP 2021년 9월 15일
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.

채택된 답변

Walter Roberson
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
Walter Roberson
Walter Roberson 2021년 9월 15일
no you need to use the version that I corrected
RP
RP 2021년 9월 15일
Thanks - I have accepted your repsonse.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by