1

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/.

John
  • 59
  • 1
  • 5

2 Answers2

1

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.

grantnz
  • 7,322
  • 1
  • 31
  • 38
1

They are not equivalent. In a callback for a checkbox, hObject refers to handles.checkbox

handles is a structure and output is only a field in it (Similarly checkbox is another field in handles). hObject is like a variable that refers to different fields of this handles structure in different callbacks.

Sreedevi
  • 98
  • 1
  • 5