How to save results matrix in multi dimensional matrix?
1 view (last 30 days)
Show older comments
I have A matrix of 9x9, B matrix of 9x1.
C is my result matrix of 9x1
I have two for loops as follows where t and e are variables used in the above mentioned matrices.
for t=25:10:45
for e=0.25:0.1:0.45
C = inv(A)*B
end
end
Now, I want result matrices for all t in first matrix ((9x1) which will be (9x9) matrix) for first variable of c and second and third (9x9)martices for second and third values of c.
.I dont know how to do. May I get help in this?
2 Comments
Jan
on 27 Feb 2023
I do not understand this sentence: "result matrices for all t in first matrix ((9x1) which will be (9x9) matrix) for first variable of c and second and third (9x9)martices for second and third values of c." What is the "first matrix"? Isn't "(9x1) which will be (9x9) matrix" a contradiction?
Where are A and B defined?
Note that inv(A)*B is less stable than A\B, so prefer the last.
Answers (1)
Stephen23
on 27 Feb 2023
Edited: Stephen23
on 27 Feb 2023
In general with MATLAB it is easier (even if more verbose) to iterate over indices rather than over data. For example:
tV = 25:10:45;
eV = 0.25:0.1:0.45;
tN = numel(tV);
eN = numel(eV);
C = cell(tN,eN);
for ii = 1:tN
for jj = 1:eN
t = tV(ii);
e = eV(jj);
.. define your matrices here
C{ii,jj} = A\B; % better than INV(A)*B
end
end
0 Comments
See Also
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!