Unable to store matrix array in for loop
显示 更早的评论
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 个评论
I suspect that you actually want to generate logarithmically spaced t values:
>> t = logspace(-4,12,17)
t =
0.0001 0.001 0.01 0.1 1 10 100 1000 10000 1e+005 1e+006 1e+007 1e+008 1e+009 1e+010 1e+011 1e+012
Compared to the rather strange linearly spaced values that you have now:
>> t = linspace(1e-4,1e12,17)
t =
0.0001 6.25e+010 1.25e+011 1.875e+011 2.5e+011 3.125e+011 3.75e+011 4.375e+011 5e+011 5.625e+011 6.25e+011 6.875e+011 7.5e+011 8.125e+011 8.75e+011 9.375e+011 1e+012
Prince Igweze
2019-11-5
Prince Igweze
2019-11-5
回答(2 个)
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
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
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!