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 Commenti

Stephen23
Stephen23 il 5 Nov 2019
Modificato: Stephen23 il 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
t is just a range of values between 10^-4 and 10^12
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.

Accedi per commentare.

Risposte (2)

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 Commento

its showing this when i run
Unable to perform assignment because the left and right sides have a different number of elements.

Accedi per commentare.

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

Categorie

Richiesto:

il 5 Nov 2019

Risposto:

il 13 Feb 2021

Community Treasure Hunt

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

Start Hunting!

Translated by