| MATLAB Function Reference | ![]() |
Store or retrieve application data
Syntax
Description
guidata(object_handle,data)
stores the variable data in the figure's application data. If object_handle is not a figure handle, then the object's parent figure is used. data can be any MATLAB variable, but is typically a structure, which enables you to add new fields as requred.
Note that there can be only one variable stored in a figure's application data at any time. Subsequent calls to guidata(object_handle,data) overwrite the previously created version of data. See the Examples section for information on how to use this function.
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.
% create structure of handles handles = guihandles(figure_handle); % add some additional data handles.numberOfErrors = 0; % save the structure guidata(figure_handle,handles)
You can recall the data from within a subfunction callback routine and then save the structure again:
% get the structure in the subfunction handles = guidata(gcbo); handles.numberOfErrors = handles.numberOfErrors + 1; % save the changes to the structure guidata(gcbo,handles)
See Also
guide, guihandles, getappdata, setappdata
| gtext | guide | ![]() |