Saving all handles behind current GUI as .mat using uiputfile style save dialogue?

Hi all,
Is there any way I can save the handles behind one of my GUI windows, using the explorer save dialogue box, like you see with uiputfile?
I am trying to avoid moving all of the handle variables one at a time to the workspace, prior to saving the workspace with uiputfile. However, I am unsure if I can adapt the uiputfile function for saving handles rather than the workspace.
Does anyone have any suggestions?
(This is unrelated to my other GUI data saving question last week which I am yet to continue working on).
Thanks in advance,
Matt

Réponses (1)

'handles' is just a variable within the workspace of every GUI callback so you can just save it like you would any other variable as
save( 'someFile.mat', 'handles' )
Whether or not it is a good idea to do is another matter, but purely from the standpoint of how to do it I don't see where the problem is.

5 commentaires

I was being stupid! Thanks.
I implemented it using
[file,path] = uiputfile('*.mat','Save Car As');
save(file, 'handles')
However when I open the .mat file I have created in Windows explorer it opens the GUI window (filled with the data I saved, phew!) three times!
Any ideas?
Adam
Adam le 5 Sep 2016
Modifié(e) : Adam le 5 Sep 2016
Could be a number of reasons. It isn't a good idea to save handles in a mat file. For a start they are huge, but also you can get things like this happening that are very difficult to get to the bottom of. If you want to save a figure you should just use savefig, according to Matlab, but if what you want is the data then saving all the graphics objects is really not good. Saving a figure works best for just a standard figure, not a complex GUIDE-based application.
You should just save the data and write code to re-initialise a new GUI from the raw data files to do this. It will take vastly less memory and you won't end up with errors from GUI objects that can't load or other similar issues.
And just to add to this, you can get the handles structure from a GUI created with guide by using
handles = guidata(guiHandle)
or by using
handles = guihandles(hFig)
for any other figures
Thanks. I made a new callback for the open button myself using uigetfile and load(). This works, opening one window instead of three.
Could you please expand on this if possible:
You should just save the data and write code
to re-initialise a new GUI from the raw data
files to do this. It will take vastly less memory
and you won't end up with errors from GUI objects
that can't load or other similar issues.
This is what I need to do with two programs I am writing I think.
That is just a case of saving data objects to mat files (whether they are classes, structs, cell arrays, individual variables, whatever they may be).
Then you can pass these into a GUI at startup as an initial state and write a function that initialises the GUI from this initial state (called from the OpeningFcn).
This is how I write most of my GUIs (though I don't usually save much to file, just store them in objects) because I allow parameter windows to be opened and closed freely and of course when they are reopened they need to represent the current state of the parameters, not a default state.
This is nice and easy with classes, but still doable with structs without much more difficulty.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Develop Apps Programmatically dans Centre d'aide et File Exchange

Question posée :

le 5 Sep 2016

Commenté :

le 5 Sep 2016

Community Treasure Hunt

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

Start Hunting!

Translated by