フィルターのクリア

Storing outputs of nested for loop in a single row

1 回表示 (過去 30 日間)
Sunny
Sunny 2018 年 10 月 17 日
回答済み: Image Analyst 2018 年 10 月 17 日
Hi, I want to store the output of this nested for loop in a single row. The value of 'f' is a number. So I am trying to store the output of 'f' for different iterations in a single row with multiple columns(depends on a number of iterations and outputs).
for k = 1:30
for l = 1:50
if exist(['ID_',num2str(k),'_file_',num2str(l),'_Var','.mat'],'file')
load(['ID_',num2str(k),'_file_',num2str(l),'_Var','.mat']);
A = A{1};
A = A / abs(eig(A));
B = B{1};
C = C{1};
f = alignment_distance(A,B,C);
end
end
end

採用された回答

Image Analyst
Image Analyst 2018 年 10 月 17 日
Here is one pretty simple way:
index = 1;
for k = 1:30
for l = 1:50
fileName = sprintf('ID_%d_file_%d_Var.mat', k, l);
fprintf('Processing %s\n', fileName);
if exist(fileName, 'file')
load(fileName);
A = A{1};
A = A / abs(eig(A));
B = B{1};
C = C{1};
f(index) = alignment_distance(A,B,C);
index = index + 1;
else
fprintf(' Skipping %s - file not found.\n', fileName);
end
end
end

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by