How to save the variables inside for loop
조회 수: 52 (최근 30일)
이전 댓글 표시
I am executing loop for k=1,2,5,6,.......100 E=produces column vector of different size; end
I need to save 'E' for each value of k;
Thanks Any help is appreciated!
댓글 수: 0
채택된 답변
jgg
2016년 1월 25일
편집: jgg
2016년 1월 25일
Es = cell(100,1)
for i = 1:100 %your loop
% do stuff; generate E
Es{i} = E
end
I'm assuming you already have the loop working, you're just trying to save the output. This will be stored in Es.
댓글 수: 3
jgg
2016년 1월 25일
It would probably be difficult; all your vectors are of different sizes, which means you can't just stack them into a big matrix. If you knew they had a max size M then you could do this:
Es = NaN(100,M);
for i = 1:100 %your loop
%do stuff, generate E
Es(1:length(E)) = E;
end
This will store E in the first elements of Es for each row; the rest will be NaN values. The problem is that this is pretty inefficient in terms of memory, but it might work. You also need to know M which is difficult.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!