How can I use a function to save main workspace variables?

I have a function that saves my figures as .fig with customized parameters in a subfolder with the same name of the figure: save_fig_cust('name_of_file'). I want this function also save all variables in the workspace to a file in the same folder. However, when I run the function, it sees only its own workspace and not the main workspace.
How can a function save the main workspace? Thanks guys, Gerrard

 採用された回答

Walter Roberson
Walter Roberson 2016 年 1 月 24 日

2 投票

evalin('base', 'save(''name_of_file.mat'')')

3 件のコメント

Gerrard
Gerrard 2016 年 1 月 24 日
Thanks Walter for this answer! Very helpful! ...but, the file gets a name "name_of_file" and I'd rather define its name from my function: save_fig_cust('name_of_file'). Can it be done?
Walter Roberson
Walter Roberson 2016 年 1 月 24 日
filename = 'name_of_file'
evalin('base', sprintf('save(''%s.mat'')', filename))
Gerrard
Gerrard 2016 年 1 月 25 日
Super! Thanks!

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

その他の回答 (0 件)

カテゴリ

質問済み:

2016 年 1 月 24 日

コメント済み:

2016 年 1 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by