| MATLAB Function Reference | ![]() |
guidata(object_handle,data)
data = guidata(object_handle)
guidata(object_handle,data) stores the variable data as GUI 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 required.
guidata can manage only one variable at any time. Subsequent calls to guidata(object_handle,data) overwrite the previously created version of GUI data.
Note for GUIDE Users GUIDE uses guidata to store and maintain the handles structure. From a GUIDE-generated GUI M-file, do not use guidata to store any data other than handles. If you do, you may overwrite the handles structure and your GUI will not work. If you need to store other data with your GUI, you can add it to the handles structure. See GUI Data in the MATLAB documentation. |
data = guidata(object_handle) returns previously stored data, or an empty matrix if nothing has been stored.
To change the data managed by guidata:
Get a copy of the data with the command data = guidata(object_handle).
Save the changed version of data with the command guidata(object_handle,data).
guidata provides application developers with a convenient interface to a figure's application data:
You do not need to create and maintain a hard-coded property name for the application data throughout your source code.
You can access the data from within a subfunction callback routine using the component's handle (which is returned by gcbo), without needing to find the figure's handle.
If you are not using GUIDE, guidata is particularly useful in conjunction with guihandles, which creates a structure containing the handles of all the components in a GUI.
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 myhandles = guihandles(figure_handle); % add some additional data myhandles.numberOfErrors = 0; % save the structure guidata(figure_handle,myhandles)
You can recall the data from within a subfunction callback routine and then save the structure again:
% get the structure in the subfunction myhandles = guidata(gcbo); myhandles.numberOfErrors = myhandles.numberOfErrors + 1; % save the changes to the structure guidata(gcbo,myhandles)
guide, guihandles, getappdata, setappdata
![]() | gtext | guide | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |