Unable to store matrix array in for loop
Show older comments
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 Comments
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
on 5 Nov 2019
Prince Igweze
on 5 Nov 2019
Answers (2)
Bhaskar R
on 5 Nov 2019
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 Comment
Prince Igweze
on 5 Nov 2019
randerss simil
on 13 Feb 2021
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
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!