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 个评论

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.

请先登录,再进行评论。

 采纳的回答

CMR = inv((k/100).*C1R+(1-(k/100)).*C0R);
instead of
CMR = inv((x/100).*C1R+(1-(x/100)).*C0R);

1 个评论

Thanks a lot! I'm actually embarassed I did not see I had x there instead of k.

请先登录,再进行评论。

更多回答(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!

Translated by