How to collect output matrix from for loop
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Singthong Pat
am 29 Sep. 2021
Kommentiert: Singthong Pat
am 29 Sep. 2021
when I get 2 matrix or n matrix from for loop
clc
n = 2;
for i=1:n
A = randi(5,3,3)
end
how to A1+A2 (A1,A2 where i = 1,2)
0 Kommentare
Akzeptierte Antwort
Chunru
am 29 Sep. 2021
If you want to accumate over different matrices
n = 10;
A = zeros(3, 3)
for i=1:n
A = A + randi(5,3,3);
end
A
If you do want to access different matrices:
A = zeros(3, 3, n);
for i=1:n
A(:, :, i) = randi(5,3,3);
end
sum(A, 3)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!