load files within a for loop
18 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Beatriz Sanchez
el 28 de En. de 2019
Comentada: Image Analyst
el 28 de En. de 2019
Hi!
so, I run my code several times with differents values for some of the parameters, and I saved those results on a .mat files on a folder. What I want to do is to load that files within a for loop so I can plot them one by one. First I create a list of those files I want to plot in the workspace called "bea" and then I tried to load them in the for loop, but is not posible because matlab dosn't recognize "bea" as a file name:
cd 'C:\Users\David\Documents\Tesis\matlab\resultados\saves' %folder where are the files I want to load
folder= dir ('*.mat')
bea={folder.name} %this give a list of the files names I want to load
for id=1:16
load (bea.mat(id)) % in here, I tried to load those files one by one
for ix= 1:rep
hold on
scatter (vec, x_mean(ix, :, 1),'b','filled')
scatter (vec, x_mean(ix, :, 2),'r', 'filled')
end
plot (vec, rep_prom1,'b')
plot (vec, rep_prom2, 'r')
set (gca, 'Xtick', vec, 'Xticklabel', vec)
[ax1,h1]=suplabel('Delta m2');
[ax2,h2]=suplabel('Densidad Poblacional','y');
[ax3,h3]=suplabel(strcat('Densidad poblacional. ', ' Alpha=' ,num2str(alpha), '. p=', num2str(p), '. Respuesta Sigmoide (s=' , num2str(2), ')') ,'t');
set(h3,'FontSize',18)
set(h1,'FontSize',14)
set(h2,'FontSize',14)
print('Densidades Promedio', '-dpng')
end
Any Idea About how to do it? is it possible to load files in a for loop? thanks
0 comentarios
Respuesta aceptada
Geoff Hayes
el 28 de En. de 2019
Beatriz - isn't folder a struct array with all files that are of extension *.mat? If that is the case, can't you just iterate over each struct in the array and load that file? Perhaps something like
cd 'C:\Users\David\Documents\Tesis\matlab\resultados\saves' %folder where are the files I want to load
myFiles = dir ('*.mat');
for k=1:length(myFiles)
myData = load(myFiles(k).name);
% plot your data
end
2 comentarios
Image Analyst
el 28 de En. de 2019
You need to extract them from the myData structure, like
rep_prom1 = myData.rep_prom1;
x_mean = myData.x_mean;
Attach one of the .mat files if you still have problems.
Más respuestas (0)
Ver también
Categorías
Más información sobre Graphics Performance 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!