How can I connect buttons in GUI?
10 views (last 30 days)
Well I have two button on GUI and I want to call/use the variables that I defined in the first button in the second one or vice versa, for example I defined in the first button that x=, y= and run it, in the second button I wrote that z=x+y, but when I try to run it it says that x and y are undefined variables.
Any idea would be a great job for me.
Adam on 10 Dec 2014
You need to attach your variables to the 'handles' structure in each callback. So, in one callback:
handles.x = 3;
handles.y = 2;
guidata( hObject, handles );
Don't forget that last line - it is what commits the handles structure back to the GUI, otherwise changes to it are local to the callback and will be lost.
Then in any other callback you can just do:
z = handles.x + handles.y;
Obviously if you also want z elsewhere put that on handles too with the guidata line also.