MATLAB: Stupid question / pass Variables in a GUI

buttoncallbackvariables

hey folks, two simple questions 😀
function GetData_Callback(hObject, eventdata, handles)
x = str3num(get(handles.editbox1,'String'))
function UseData_Callback(hObject, eventdata, handles)
y = x +1
disp(y)
How can I pass x form the 1st Button to the 2nd Button ?

Best Answer

Do you necessarily need to create x in the GetData_Callback? Why not just in the UseData_Callback? If you really need it this way, just initialize the variable x in the main function (before the callbacks start). Then the variable will be valid in the entire file (in all subfunctions).