Saving multiple function outputs into respective cells in for loop
1 view (last 30 days)
Show older comments
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!
0 Comments
Accepted Answer
Walter Roberson
on 24 Sep 2015
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
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!