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

4 ビュー (過去 30 日間)
Luqman Saleem
Luqman Saleem 2018 年 4 月 28 日
コメント済み: Luqman Saleem 2018 年 4 月 30 日
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?

採用された回答

Rik
Rik 2018 年 4 月 28 日
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 件のコメント
Rik
Rik 2018 年 4 月 28 日
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.
Luqman Saleem
Luqman Saleem 2018 年 4 月 30 日
Thank you so much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by