Borrar filtros
Borrar filtros

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

9 visualizaciones (últimos 30 días)
Kevin Burg
Kevin Burg el 23 de Jul. de 2021
Respondida: Image Analyst el 23 de Jul. de 2021
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

Respuesta aceptada

Simon Chan
Simon Chan el 23 de Jul. de 2021
use the following for saving data into a file.
save(fullFileName, 'plotvars'); % plot vars is the variable I want to save

Más respuestas (1)

Image Analyst
Image Analyst el 23 de Jul. de 2021
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().

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by