Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
i have a two dimensional matrix inside a loop i want to save the data matrix inside the loop so that each time the loop runs the data doesn't gets overwritten with the next one what should i do?
조회 수: 1 (최근 30일)
이전 댓글 표시
the value inside the loop is a two dimensional matrix that i need save every time
댓글 수: 2
답변 (2개)
Jan
2018년 7월 4일
To store 100 matrices of size 3x4:
n = 100;
Result = zeros(3, 4, n);
for k = 1:n
Result(:, :, k) = rand(3, 4); % Replace rand by your data
end
Or if the matrices have different sizes, use a cell array:
n = 100;
Result = cell(1, n);
for k = 1:n
Result{k} = rand(2, k);
end
댓글 수: 0
Kulan Sinclair
2018년 7월 4일
you can do it as either a cell array
for i = 1:10
matrix = rand(10,10);
matrixcellarray{i} = matrix;
end
or a structure
matrixName = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
for i = 1:numel(matrixName)
matrix = rand(10,10);
matrixStructure.(matrixName{i}) = matrix;
end
which is more useful depends on what you are trying to do with the data
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!