필터 지우기
필터 지우기

load files within a for loop

조회 수: 8 (최근 30일)
Beatriz Sanchez
Beatriz Sanchez 2019년 1월 28일
댓글: Image Analyst 2019년 1월 28일
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

채택된 답변

Geoff Hayes
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
Beatriz Sanchez
Beatriz Sanchez 2019년 1월 28일
thank you for your answer!
I did what you told me to, but now when I run the code, it dosn't give me any plot, it says "undefined function or variable ...." and those "undefined" variables are the ones that supposed to be on the files that I'm loading.
Image Analyst
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 CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by