Make a new a directory and save a file in a loop

11 ビュー (過去 30 日間)
Kevin Burg
Kevin Burg 2021 年 7 月 23 日
回答済み: Image Analyst 2021 年 7 月 23 日
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

採用された回答

Simon Chan
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

その他の回答 (1 件)

Image Analyst
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().

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by