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 件のコメント

William Rose
William Rose 2022 年 9 月 12 日
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.

サインインしてコメントする。

 採用された回答

Torsten
Torsten 2022 年 9 月 12 日

0 投票

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

1 件のコメント

DK
DK 2022 年 9 月 12 日
Thanks a lot! I'm actually embarassed I did not see I had x there instead of k.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

DK
2022 年 9 月 12 日

コメント済み:

2022 年 9 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by