Saving multiple function outputs into respective cells in for loop

1 次查看(过去 30 天)
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