Effacer les filtres
Effacer les filtres

Saving multiple function outputs into respective cells in for loop

2 vues (au cours des 30 derniers jours)
Brian
Brian le 24 Sep 2015
Commenté : Brian le 24 Sep 2015
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!

Réponse acceptée

Walter Roberson
Walter Roberson le 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
  1 commentaire
Brian
Brian le 24 Sep 2015
Thank you for the response! This worked like a charm!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by