save figure as .mat to a different folder

5 ビュー (過去 30 日間)
Vincent I
Vincent I 2013 年 8 月 8 日
Hi, I would like to save a figure as a mat file to a different folder other then the current folder. Simpfied code:
str = sort(get(findobj(0,'Type','figure'),'name'));
[s,v] = listdlg('PromptString','Select a file:',...
'SelectionMode','single',...
'ListString',str);
fig = handle2struct(figure(s));
save('Path to the folder',fig)
I've tried save(['Path'],fig) etc but nothing worked
Thank you
  1 件のコメント
Jan
Jan 2013 年 8 月 8 日
Instead of the vague "nothing works" it is better to explain what happened instead. Most of all the error message would reveal the problems.

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

採用された回答

Jan
Jan 2013 年 8 月 8 日
編集済み: Jan 2013 年 8 月 8 日
save('Path to the folder', 'fig')
The fig must be enclosed in quotes.
This is a frequently occurring problem, see Answers: Magic Strings, SAVE is not magic
Btw, FIG files have MAT format also, so you can store the FIG file by saveas and import it as struct by:
S = load('YourFile.fig', '-mat');

その他の回答 (1 件)

Vincent I
Vincent I 2013 年 8 月 12 日
is there a way to save the figure and the workspace at a predetermined location using the folowing code?
fig = handle2struct(figure(s));
Dir = strcat('D:\Documents and Settings\...\Save\',folder,'.mat');
assignin('base','SavedFig',fig)
evalin('base', 'save(''Dir'')')
right now the ws is saved in the current folder and not in the Dir folder. Thank you
  1 件のコメント
Vincent I
Vincent I 2013 年 8 月 12 日
NVM i got it:
location='c:\afefefedf';
evalin('base', ['save(''', location ''')']);

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

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by