How can I connect buttons in GUI?

6 次查看(过去 30 天)
Hello,
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=[3], y=[2] 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
Adam 2014-12-10
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.
  4 个评论
Adam
Adam 2017-7-24
Which part of the answer isn't clear.
Connecting data up in a Matlab GUI is covered in detail here
Sairah
Sairah 2017-7-26
Actually Adam I want to link my data which is read from text file operates by two buttons one is by push button and second from checkbox so I wonder how to share that data between the two buttons and I am using GUIDE so not creating programatic GUI

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by