I think that nested functions are the simplest and most intuitive way of passing data between GUI callback functions: function mainGUI()
...
p1 = [];
p2 = [];
p3 = [];
function Selection1_Callback (hObject, eventdata)
p1 = ...
end
function Selection2_Callback (hObject, eventdata)
p2 = ...
end
function Selection3_Callback (hObject, eventdata)
p3 = ...
end
function pushbutton_Callback (hObject, eventdata)
p4 = p1 + p2 + p3;
set(edit, 'String', num2str(p4))
end
end
For other ways of passing data between callback functions you can read the MATLAB documentation:
Note: avoid global and assignin: these will not help you to write good code.
Best Answer