load files within a for loop
10 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Geoff Hayes
2019 年 1 月 28 日
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 件のコメント
Image Analyst
2019 年 1 月 28 日
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.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!