Save base workspace MAT file from GUI

Guys -
I'm writing a GUI in which I'd like to put a pushbutton to save the entire base workspace to a .mat file. Problem is I don't know how to do that from the GUI subfunction workspace. Can anyone point me to the right approach or write a couple lines I can put in the pushbutton's callback function to save the base workspace as .mat?

 채택된 답변

Jan
Jan 2011년 11월 18일

1 개 추천

I do not think, that this method have enough control over what is written. But if you really want to save the base workspace to a MAT file:
evalin('base', 'save(''FileName.mat'')');

댓글 수: 3

Jason
Jason 2011년 11월 18일
Thanks Jan, I was having trouble with the syntax in nesting the save command properly. Now, how do I do it if in a different location in my code I specify a filename string and I want to execute your line using a previously-defined filename?
Jan
Jan 2011년 11월 18일
FileName = 'test.mat';
evalin('base', ['save(''', FileName ''')']);
Jason
Jason 2011년 11월 19일
Thanks Jan, you rock!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Naz
Naz 2011년 11월 19일

0 개 추천

Here is what I would do: for saving a particular set of variables in the struct you can create a struct and save it:
structDATA=struct('your1var',handles.your1var,'your2var',handles.your2var);
save ('filename', 'structDATA');
If you want to save all the variables from handles, then just do:
save ('filename', 'handles');
I hope this will work

댓글 수: 2

Jason
Jason 2011년 11월 19일
Thanks Naz.
Mohamed Sarillee
Mohamed Sarillee 2013년 1월 31일
thank you.... :-)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

질문:

2011년 11월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by