Saving multiple function outputs into respective cells in for loop

조회 수: 1 (최근 30일)
Brian
Brian 2015년 9월 24일
댓글: Brian 2015년 9월 24일
I have a function, nps2d that returns 4 outputs [nps,f,nps2,fx,fy]. I would like to save each of the 4 outputs in respective cells of a variable so I can process them further.
It looks something like:
npsout={};
for i = 39:140
npsout{end+1} = nps2d(im{i}(230:290,62:122),info.PixelSpacing(1)*size(im{40},1)/size(y{40}{2},1));
end
I would like npsout to contain 4 cells to include each output [nps,f,nps2,fx,fy]. It would be lovely that a given cell contains information from i = 39:140. Perhaps, something like npsout{1}{3} is the nps output of i = 42. And npsout{2}{1} is the f output of i = 39.
The end+1 doesn't work here because it only captures a single output. Please help. Thank you so much!

채택된 답변

Walter Roberson
Walter Roberson 2015년 9월 24일
npsout=cell(5,1);
for i = 39:140
[nps,f,nps2,fx,fy] = nps2d(im{i}(230:290,62:122), info.PixelSpacing(1) * size(im{40},1) / size(y{40}{2},1));
npsout{1}{end+1} = nps;
npsout{2}{end+1} = f;
npsout{3}{end+1} = nps2;
npsout{4}{end+1} = fx;
npsout(5}{end+1} = fy;
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by