MATLAB: What’s the difference between handles and hObject

handles hobject function eventdata matlab values gui

Where do I use handles and hObject?? And why are there function which contain sometimes both of them plus eventdata and other one of those 3 is missed?? for example function pushbutton1_Callback(hObject, eventdata, handles)

Best Answer

hObject is the handle to the calling object; i.e. the object that is calling the function. handles is a structure with all of the handles to all objects.
The only time I use hObject is if I have two objects sharing a callback, e.g. pushbutton1 and pushbutton2 both call foo_Callback. In this scenario, I would use hObject to determine which one called or if we needed to modify the calling object.
Related Question