execute a loop with diffrent name
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Rica
el 25 de Feb. de 2015
Hi All,
the name of my data are :
data50_1.mat data50_2.mat......data50_100.
data86_1.mat data80_2.mat......data80_100.
and i have these loop
for k=1:100
A=struct2cell(load (['data50_' num2str(k) '.mat']));
end
My question How could i use the loop for data86 using some tricky indexing?
I have not only data50_... and data86_..., but i have more data set.
Thank you
0 comentarios
Respuesta aceptada
Stephen23
el 25 de Feb. de 2015
Editada: Stephen23
el 25 de Feb. de 2015
for k1 = [50,86]
for k2 = 1:100
file_name = sprintf('data%u_%u.mat',k1,k2);
load(file_name)
end
end
Currently your code will completely replace the data from the previous loop, as on every iteration it assigns new data to the variable A. If you wish to avoid this, then you need to use some indexing to store all of the data, or consider using a structure and dynamic field names to store the load data directly:
A = struct([]);
for k1 = [50,86]
for k2 = 1:100
file_name = sprintf('data%u_%u.mat',k1,k2);
A(k2).(sprintf('data%u',k1)) = load(file_name);
end
end
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!