Creating Graphical User Interfaces | ![]() ![]() |
If You Are Not Using a Handle Structure
If you are writing your own application M-file and are not generating a handle
structure, you can still use the GUI figure's application data for storing any data that you want to pass between subfunctions. This mechanism involves:
Using the guidata Function
The guidata
function provides a convenient interface to the figure's application data. It enables you to access the data without having to find the figure's handle (something that may be difficult when the handle is hidden) and avoids the need to create and maintain a hard-coded property name for the application data throughout your source code.
For example, you would set up the code similar to this.
fig = openfig(mfilename,'new');% open GUI and save figue handle
. . . data.field1 = value1;% create a structure
guidata(fig,data)% save the structure
Within a callback subfunction:
data = guidata(gcbo);% load the data
data.field1 = new_value;% change the structure
guidata(gcbo,data)% save the structure
Note that, once a callback routine has begun execution, guidata
can obtain the handle of the figure using gcbo
(the handle of the object whose callback has been called). However, in the initialization section, no callback routine has been invoked so you cannot use gcbo
. In this case, you can use the handle of the GUI figure returned by openfig
.
![]() | Managing GUI Data | Application-Defined Data | ![]() |