Purpose of guidata(hObject,handles)
Show older comments
I've been working with GUI GUIDE.
What is the purpose or role of guidata(hObject,handles)?
Thanks,
Amanda
Accepted Answer
More Answers (2)
This stores the variable named 'handles' in the guidata of the object with handle HObject.
I assume you saw this in the Openfcn of a GUIDE GUI, correct? If so, then this line is simply storing a structure called 'handles', which contains the handles to all visible graphics objects, in the guidata of the figure. From anywhere else you can access this structure by calling GUIDATA(hfig). For example, say you have a GUIDE GUI named mygui. Do this at the command line:
H = mygui; % Returns the handle of the figure into H.
guidata(H)
arestw ali
on 25 Oct 2015
0 votes
hello everyone what is the different between (hObject, eventdata, handles, varargin) how can i related between for exmp. the pushbutton and pop,text,axis thanx a lot
1 Comment
Walter Roberson
on 25 Oct 2015
hObject is the handle to the object whose callback is being executed.
eventdata is empty for most kinds of callbacks, but for some kinds of callbacks it gives additional information about what triggered the callback. For example a key press function callback will have information about which key sequence triggered the callback.
handles, in the context you use, is a structure containing whatever data has been stored in it. When you are using GUIDE, at the very least it will have one field for every graphics object you created using GUIDE, with the field named the same as the Tag you used for the object. For example if you have a pushbutton1 and an editbox1 then handles would be a structure with fields "pushbutton1" and "editbox1", and the value of those fields created by default would be the handles of the respective graphics object. It is common to also store other non-handle information into handle, such as the way Sven showed storing a counter there.
varargin is for variable length argument data; see http://www.mathworks.com/help/matlab/ref/varargin.html. It allows the routine to be programmed to accept optional parameters.
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!