Store my for loop in single vector
이전 댓글 표시
I'm trying my best to get my equation into a 1x100 array. However, I only get the same number returned in every cell, for x=100.
C1R and C0R are 9x9 matrices with both positive and negative scalars.
x=100;
Result = zeros(1, x);
for k = 1:x
CMR = inv((x/100).*C1R+(1-(x/100)).*C0R);
last = CMR(9,9);
Result(k) = last;
end
I obtain a 1x100 array with all cells filled for x=100, instead I want:
Cell 1x1: value for x=1, Cell 1x2: value for x=2, etc. Just to clarify, manually calculating outside the loop does return different values. I only need each value in Cell 9,9 from CMR in the 1x100 array.
I have no clue how to tackle this, or how to solve my for loop. Any ideas?
댓글 수: 1
@DK,
I assume C0R and C1R are 9x9 arrays.
C0R=rand(9,9);
C1R=rand(9,9);
x=100;
Result = zeros(1, x);
for k = 1:x
CMR = inv(k*C1R/100+(1-k/100)*C0R);
Result(k)=CMR(9,9);
end
plot(Result)
Try the above.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 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!
