Storing outputs of nested for loop in a single row

1 Ansicht (letzte 30 Tage)
Sunny
Sunny am 17 Okt. 2018
Beantwortet: Image Analyst am 17 Okt. 2018
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

Akzeptierte Antwort

Image Analyst
Image Analyst am 17 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by