Make a new a directory and save a file in a loop
조회 수: 5 (최근 30일)
이전 댓글 표시
I am post-processing 36 different cases. What I want to do is run the script, save the variable of interest, create a new directory with the case number, then save the mat file and associated post-processing files in that new directory.
I am running into a problem with the save command. I am getting that I am passing in too many arguments. I'm not sure how I can specify the variable of interest that I am trying to save otherwise though. Any better ways to do this? Thanks for the help!
folder = 'C:Users\me\Documents'
for ind_bet=1:36
run_analysis(); % run script
save_plot_vars; % script to save plotting variables
fullFileName = sprintf('./plotvars_%d/plotvars_%d.mat', ind_bet);
j{ind_bet} = save(fullFileName, 'plotvars'); % plot vars is the variable I want to save
post() % post processing script
cd folder % cd back to original directory and start over
end
댓글 수: 0
채택된 답변
Simon Chan
2021년 7월 23일
use the following for saving data into a file.
save(fullFileName, 'plotvars'); % plot vars is the variable I want to save
댓글 수: 0
추가 답변 (1개)
Image Analyst
2021년 7월 23일
The save() function does not return anything. So you cannot take it's output (of which there is none) and stuff it into j{ind_bet}. Perhaps you really wanted to save filenames???
j{ind_bet} = fullFileName; % Save this filename into a cell array.
save(fullFileName, 'plotvars'); % Don't accept any output arguments when you call save().
댓글 수: 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!