function main_OpeningFcn(hObject, eventdata, handles, varargin)
SubCallbacks = SubCallbacks_Cntrl;
set(handles.checkbox1, 'Callback', SubCallbacks.checkbox1_Callback)
set(handles.pushbutton1, 'Callback', SubCallbacks.pushbutton1_Callback)
Then add this in each callback to obtain the current value of the handles struct:
function checkbox1_Callback(hObject, evt)
handles = guidata(hObject);
...
Alternatively you can use a wrapper function: Define the same function for all callbacks and branch by using an additional argument:
function SubCallbacks_Cntrl(hObject, EventData, ObjectName)
handles = guidata(hObject)
switch ObjectName
case 'pushbutton1'
pushbutton1_Callback(hObject, EventData, handles)
case 'checkbox1'
checkbox1_Callback(hObject, EventData, handles)
...
end
And the single callbacks are following. You could use the tag of the object also:
Best Answer