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 Comment

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.

Sign in to comment.

 Accepted Answer

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

1 Comment

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

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

DK
on 12 Sep 2022

Commented:

on 12 Sep 2022

Community Treasure Hunt

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

Start Hunting!