MATLAB: Hi everyone Is there any way to pass more than one variables with different data types through the UserData Property for any UIcontrol in GUI

gui userdata

function pushbutton1_Callback(hObject, eventdata, handles)
% i need to pass both a and b to another callback
a=30;
b='address';
set(hObject,'UserData',a);
set(hObject,'UserData',b);

Best Answer

set(hObject, 'UserData', struct('a', a, 'b', b) );
or
data_to_pass.a = a;
data_to_pass.b = b;
set(hObject, 'UserData', data_to_pass )
You can also use cell arrays or numeric arrays, depending on the data types.