Data saving for a loop
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a code like this:
for i=1:n
%calculuse
for j=1:n
%calculus
for k=1:n
%calculus
Save results in a matrix
end
end
end
I want to save the matrix inside a bigger matrix with matrix elements for each loop inside dhe interioe loop (k=1:k)
Thank you in advance
댓글 수: 0
채택된 답변
William
2021년 1월 25일
Nertila -- Yes, that is what this code does. Maybe it would be more clear if I wrote it in this way, with the k-index being the outer loop rather than the inner loop. In each iteration of the k-loop, an S(i,j) matrix is computed in the i and j loops, and then stored in a(k,:,:).
a = zeros(n,n,n);
S = zeros(n,n);
for k = 1:n
for i = 1:n
%calculus
for j = 1:n
calculus
S(i,j) = ...
end
end
a(k,:,:) = S;
end
추가 답변 (1개)
William
2021년 1월 23일
a = zeros(n,n,n)
for i=1:n
%calculus
for j=1:n
%calculus
for k=1:n
%calculus
a(i,j,k) = result(k)
end
end
end
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!