Create a folder for each iteration and save workspace and figures
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello, I need to save the workspace and figures for each iteration. The resulting workspace and figures should be placed in a new folder for each iteration. The iterations are a function of two parameters A and B, so I have two 'for' loops.
For IdxParaA=1:length(ParaA)
For IdxParaB=1:length(ParaB)
alpha=ParaA(IdxParaA)
beta=ParaB(IdxParaB)
...stuff to run...
%HERE NEED TO CREATE A FOLDER AND SAVE BOTH WORKSPACE + FIGURES
cd('C:\Output\Results_"value of IdxParaA"_"value of IdxParaB"
cd('C:\Program')
end
end
I have 5 values for ParaA and 4 values for ParaB so in the end I need to have 20 folders named as:
C:\Output\Results_1_1
C:\Output\Results_1_2
...
C:\Output\Results_1_4
... ...
C:\Output\Results_5_4
Please let me know if this is not clear or there is a post that answers it
댓글 수: 0
답변 (3개)
Star Strider
2015년 4월 17일
I wouldn’t save them each in a different directory, simply a different .mat file. See the documentation for save, load, and matfile for details. You’ll have all your variables — regardless of type — in each .mat file, and you’ll be able to load all or some of the variables into your workspace as you need them later.
댓글 수: 0
Sarmed Wahab
2022년 9월 3일
이동: Stephen23
2022년 9월 3일
I am posting this for people finding relative answer.
for i = 1:5
x = rand(10,1) ;
y = 3*x + i^2 ;
plot(x,y,"bo"); hold on;
a = plot(x,y) ; hold off;
dest_dir = "C:\folder\PROJECT DATA\figure" + i ;
mkdir(dest_dir);
filename = "plot"+string(i)+".png";
% saveas(fig,filename)
fig_file = fullfile(dest_dir , filename)
%saveas(a, filename) %save the file there directory
saveas( a, fig_file)
result = "results"+i;
matfile = fullfile(dest_dir, result);
save(matfile);
%save(result)
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Printing and Saving에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!