matlabmatlab-guidehandlesmatlab-gui

In MATLAB's GUIDE, is guidata(hObject) the same as guidata(handles.output)?


When using GUIDE, in a callback function such as

function checkbox_Callback(hObject, eventdata, handles)

will

guidata(hObject)

and

guidata(handles.output)

return the same struct?

Similarly, will

guidata(hObject, handles)

and

guidata(handles.output, handles)

save changes made to the handles struct to the same "place"?

In other words, is using hObject versus handles.output for guidata equivalent?

handles.output returns a "handle to the main interface" - see http://www.matlabtips.com/guide-me-in-the-guide/.


Solution

  • Yes, because the guidata function includes the following call

    fig = getParentFigure(h)
    

    to ensure that it is operating on a figure handle even if you supply it with the handle of a figure child element (e.g. a checkbox handle).

    The handles structure is stored in the application data of the figure (i.e. the data that the guidata function updates) so subsequent callbacks will receive your updated handles structure.