How to save all workspace variables and figures in a folder?

Hello there, I want to write a code which will save all workspace variables and figures in separate folders.
For example if I am currently in folder C:\Users\XXX\Documents
I want MATLAB to create a folder named 'ED' in 'Documents' and then create subfolder named '['N=',num2str(N)]' and further create two subfolders in '['N=',num2str(N)]' folder named 'Data' and 'Figures' and then save all workspace variables in folder 'Data' and figures in folder 'Figures'.
Is it possible in MATLAB?

 Accepted Answer

You can save all variables in the current workspace by using save without specifying any variable name, although this is inadvisable outside of debugging.
Other functions you might want to look into: sprintf, mkdir, savefig, and fullfile

5 Comments

I tried with 'mkdir' but I could not create subfolders in subfolder.
What code did you try for mkdir? Because it shouldn't have any trouble creating subfolders in folders that don't exist yet. What error are you getting?
N=10;
mkdir('ED',['N=',num2str(N)])
I want to further create subfolders in N=10 folder. How can I do that?
You can either use a relative path (first block of code), or a complete path.
N=10;
new_folder=fullfile('ED',sprintf('N=%d',N),'variables');
mkdir(new_folder)
N=10;
current_folder=pwd;
new_folder=fullfile(current_folder,'ED',sprintf('N=%d',N),'variables');
mkdir(new_folder)
mkdir will create any non-existing intermediary folders.

Sign in to comment.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Asked:

on 28 Apr 2018

Commented:

on 30 Apr 2018

Community Treasure Hunt

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

Start Hunting!