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 commentaire

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.

Connectez-vous pour commenter.

 Réponse acceptée

Torsten
Torsten le 12 Sep 2022
CMR = inv((k/100).*C1R+(1-(k/100)).*C0R);
instead of
CMR = inv((x/100).*C1R+(1-(x/100)).*C0R);

1 commentaire

DK
DK le 12 Sep 2022
Thanks a lot! I'm actually embarassed I did not see I had x there instead of k.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by