how to interrogate handle

7 visualizzazioni (ultimi 30 giorni)
Yu-Chiu Chao
Yu-Chiu Chao il 18 Mag 2016
Commentato: Yu-Chiu Chao il 21 Mag 2016
I am working on a GUI and associated program written by someone else. It would be useful if, while executing the GUI, I can monitor the evolution of variables used in the program in real time from the interactive window. I don't know how to access them though. For example for something like handle.data.val, how can I see its value by commands issued in the interactive window?

Risposta accettata

Walter Roberson
Walter Roberson il 18 Mag 2016
openvar('handle')
In the command window, provided that handle is in scope, you can use
handle.data.val
Note: if it is a GUI, then it is more likely that the variable is named handles and that data is the handle of a uicontrol, and that you want to look at its Value or String. If you are using up to R2014a you would use
get(handles.data, 'Value')
get(handles.data, 'String')
From R2014b onward you can also use
handles.data.Value
handles.data.String
  3 Commenti
Walter Roberson
Walter Roberson il 20 Mag 2016
When you are building a GUI using GUIDE, handles is a parameter to each function, and it only exists until the function exits, so unless you put in a breakpoint in the routine of interest, you cannot truly look at it.
handles is not a global variable: it is something that is built at run-time just as each routine is called.
However, the way that GUIDE works with handles is that for each GUI, there is a "master copy" of the handles structure. At any time the code can request a copy of what is currently stored in the "master copy". That becomes a local copy that lives in the workspace of the one function, and the local copy will be destroyed when the function returns. You can make any number of changes to the local copy without there being any change to the master copy.
However, inside a function, if you have your local structure named handles, then if you happen to call
guidata(hObject, handles); %writes to master copy
or equivalent, then that local version will overwrite the "master copy". That will not affect any local copies that might happen to still exist: if you have a local copy of handles and you have reason to suspect that some other routine might have changed the master copy while you are still running, then you need to ask for an updated local copy of the master copy,
handles = guidata(hObject); %fetches from master copy
You can do that fetching of the master copy when you are at the MATLAB command line, but for hObject you would substitute the figure number of the GUI:
handles = guidata(gcf);
Yu-Chiu Chao
Yu-Chiu Chao il 21 Mag 2016
Hi Walter, Thanks a lot! This is very useful!
YC

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by