Storing outputs of nested for loop in a single row

1 visualización (últimos 30 días)
Sunny
Sunny el 17 de Oct. de 2018
Respondida: Image Analyst el 17 de Oct. de 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

Respuesta aceptada

Image Analyst
Image Analyst el 17 de Oct. de 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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by