# Unable to store matrix array in for loop

4 views (last 30 days)
Prince Igweze on 5 Nov 2019
Commented: Prince Igweze on 5 Nov 2019
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

Stephen Cobeldick on 5 Nov 2019
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
t is just a range of values between 10^-4 and 10^12
Prince Igweze on 5 Nov 2019
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.

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
its showing this when i run
Unable to perform assignment because the left and right sides have a different number of elements.