Storing outputs of nested for loop in a single row

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops 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