Saving base workspace to .mat file multiple times in GUIDE GUI

Hi,
From looking at previous threads, I've seen how you save the workspace to a file (thank you Jan Simon) but I was wondering if you could do this more than once.
I would like my user to be able to change a load of variables in the GUI, and if they like the outputs, be able to save that data to an .mat file. Then, if they have another fiddle and want to save some more data, it would save to a seperate .mat file.
Is this possible? Or is there a quick trick to writing the code to make it work elegantly?
Thanks,

2 comentarios

Do you really mean "save it to a .mat file"? A .m file is a file containing code, not data.
Yes, sorry, I'll edit the question.
thanks

Iniciar sesión para comentar.

 Respuesta aceptada

Guru
Guru el 4 de Jul. de 2013
Yes it's possible.
All you really need is to have a means to choose what to name your MAT-file from your GUI.
This can be done by having an Edit textbox control in your GUI, or using some other means with the UI controls to prompt the user for a filename.

4 comentarios

I've tried this but can't seem to get it to work:
evalin('base', 'save(''get(handles.edit26,'string')'')');
or even putting the input values into a variable and then trying it that way
evalin('base', 'save('''a'.mat'')');
Am I doing something obvious wrong?
Wait, you mean your GUI is sending the output data to the base workspace and then you are trying to save the base workspace to a MAT file? My question would be why are you not simply keeping the data in the GUI workspace as you are using GUIDE and saving the data variables to the MAT file instead.
To answer your comment more directly, yes you are doing something obviously wrong. SAVE expects a string input of the filename, but what you are giving it:
save(''get(handles.edit26,'string')'')
save('''a'.mat'')
is a variable that represents the string. This should work instead
save(get(handles.edit26,'string'))
save([a, '.mat'])
as get(handles.edit26,'string') will return a string of what was typed in that EDIT UICONTROL, which can then be fed directly into SAVE
the edit26 box is the box i want the user to input the name s/he wants the mat file to be called.
i want to save the whole base workspace rather than the handles individually, as there's a large amount of editable (through the GUI) in the workspace along with other uneditable data and variables whos values depend on both these sets of data.
So the user can load all his/her previous data easily for future use.
Thanks for the help
Well place the save command code I put in the previous comment with your evalin commands. That should work.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Preguntada:

el 4 de Jul. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by