How to collect output matrix from for loop
조회 수: 10 (최근 30일)
이전 댓글 표시
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
채택된 답변
Chunru
2021년 9월 29일
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)
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!