フィルターのクリア

Saving multiple function outputs into respective cells in for loop

2 ビュー (過去 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
  1 件のコメント
Brian
Brian 2015 年 9 月 24 日
Thank you for the response! This worked like a charm!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by