MATLAB Function Reference | ![]() ![]() |
Store or retrieve application data
Syntax
guidata(object_handle,data) data = guidata(object_handle)
Description
guidata(object_handle,data)
stores the specified data in the figure's application data. If object_handle is not a figure handle, then the object's parent figure is used.
data = guidata(object_handle)
returns previously stored data, or an empty matrix if nothing has been stored.
guidata
provides application developers with a convenient interface to a figure's application data:
gcbo
), without needing to find the figure's handle. guidata
is particularly useful in conjunction with guihandles
, which creates a structure in the figure's application data containing the handles of all the components in a GUI.
Examples
In this example, guidata
is used to save a structure on a GUI figure's application data from within the initialization section of the application M-file. This structure is initially created by guihandles
and then used to save additional data as well.
data = guihandles(figure_handle); % create structure of handles data.numberOfErrors = 0; % add some additional data guidata(figure_handle,data) % save the structure
You can recall the data from within a subfunction callback routine and then save the structure again:
data = guidata(gcbo); % get the structure in the subfunction data.numberOfErrors = data.numberOfErrors + 1; guidata(gcbo,data) % save the changes to the structure
See Also
guide
, guihandles
, getappdata
, setappdata
![]() | gtext | guide | ![]() |