Unable to store matrix array in for loop

2 ビュー (過去 30 日間)
Prince Igweze
Prince Igweze 2019 年 11 月 5 日
回答済み: randerss simil 2021 年 2 月 13 日
t = linspace(10^-4,10^12,17)
for i = 1:17
m = inv((At * Cd * A) + (t(i) * Ht * H)) * At * Cd * do
end
Solution for m is a 20 by 1 matrix
but im having issues storing each iteration of the solution as an individual set (i.e m1 , m2, m3 ....m17)
it just lumps all the solutions as m
making it unable for me to call out a solution of choice
  3 件のコメント
Prince Igweze
Prince Igweze 2019 年 11 月 5 日
t is just a range of values between 10^-4 and 10^12
Prince Igweze
Prince Igweze 2019 年 11 月 5 日
that seems to make more sense.
Stephen, any ideas on how I can store each solution in the loop as M(1), M(2) .....M(17)
rather than M.

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

回答 (2 件)

Bhaskar R
Bhaskar R 2019 年 11 月 5 日
t = linspace(10^-4,10^12,17);
m = zeros(length(t),1); % initialize with zeros
for i = 1:17
m(i) = inv((At * Cd * A) + (t(i) * Ht * H)) * At * Cd * do; % store values for each iteration
end
  1 件のコメント
Prince Igweze
Prince Igweze 2019 年 11 月 5 日
its showing this when i run
Unable to perform assignment because the left and right sides have a different number of elements.

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


randerss simil
randerss simil 2021 年 2 月 13 日
t = linspace(10^-4,10^12,17)
for i = 1:17
m{i} = inv((At * Cd * A) + (t(i) * Ht * H)) * At * Cd * do ; % use cell array
end
Use cell array as above

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by