Storing outputs of nested for loop in a single row

1 view (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 17 Oct 2018
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

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!