Loading .mat file from within GUI not doing anything?!
Afficher commentaires plus anciens
Hi,
I have made a simple concept GUI to test populating a drop down menu based on the .mat files in a directory, and then loading the selected .mat file.
My code (attached - change the directory to where you save it...) is notdoing anything when I try to load the .mat file.
On the other hand if I type in the command window:
handles.Selection = 'Data2.mat'
load(handles.Selection)
It loads fine... Why is this? I'm lost!
Thanks,
Matt
5 commentaires
Adam
le 6 Sep 2016
What do you mean by not doing anything? What are you expecting? It should load into the workspace of whatever callback you have the code in.
Matt
le 6 Sep 2016
Henry Giddens
le 6 Sep 2016
Are you sure it hasnt just loaded the variables in the .mat file into the workspace of your 'LoadDataButton_Callback', which are then cleared when you exit this function. Have you tried putting a break point on the last line of your code to check?
Matt
le 6 Sep 2016
Henry Giddens
le 6 Sep 2016
Modifié(e) : Henry Giddens
le 6 Sep 2016
Hi Matt, I'm going to try and attempt to explain this, but it may not be very clear...
Think of Matlab as having a list of functions that need to be executed. Your GUI is a simple function that has to run. When a GUIDE GUI is launched it runs through the opening function and then the output function and then the list of functions left for matlab to execute is empty. Control is handed back to the command window.
Now, to get an output from a gui where the user has interacted to influence what that output is, the uiwait(hObject) command is used to halt any further execution of matlab's list of functions, until the gui is closed (or uiresume is called). The outputfcn in the gui '.m' file can be modified so that when it executes, an output is returned from the gui function, that depends on how the user used that gui.
Take a look at some of matlabs inbuilt gui functions to distinguish between gui functions that return an output based on how the user interacted with the gui, and those that don't.
For examples of the first:
uigetfile
menu
examples of the second
errordlg
If (and I'm guessing here) you want to create a GUI that populates the base workspace every time you click the load button, then this isn't really possible. You would have to close the gui once the file has been selected*, outputting the relevant data via the output_fcn (or in this case it would be more sensible to output the path to the file, and load the data afterwards)
Maybe take a look at this video for getting outputs from guide GUIs (I haven't actually watched it but i imagine it explains how it works). http://blogs.mathworks.com/videos/2010/02/12/advanced-getting-an-output-from-a-guide-gui/
*You dont actually have to close the gui, only to call uiresume, for the output_fcn to execute. However, leaving the gui open would be a bit misleading/pointless
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming Utilities dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!