GUIDE - How to use variables that are calculated in Button 1, in Button 2?

4 次查看(过去 30 天)
I am finding it difficult to understand how this is done, I have read some posts and answers on it but I am even more confused with the answers. I have a GUI made in GUIDE.
  • I have one button, it reads some values that are input by the user and does some calculations.
  • I then have a second button and I want to use the calculations from button 1 in the second button...
I am familiar with having a workspace and seeing all my variables but I am not finding GUIDE intuitive. Please can someone advise

采纳的回答

Adam
Adam 2018-9-26
This gives various different methods and examples. I use the guidata approach if I am using a GUIDE GUI.
  3 个评论
Stephen23
Stephen23 2018-9-27
编辑:Stephen23 2018-9-27
"Is there a simpler way to do this without having to spend days going over the details?"
Not really, because actually writing asynchronous code is not a trivial task, and all GUI's are fundamentally asynchronous. Making data accessible to different parts of asynchronous code is more complex than passing data in a simple linear program. Sure, you will have to learn some new things, but it is really not that hard. Start by trying the examples from the documentation, or download some of the examples available on MATLAB File Exchange:
On a more practical note, I would recommend avoiding GUIDE and writing your own code, then you can use nested functions for all of the callback functions to make passing that data around easy (structures are not required!).
If you really want to use GUIDE, then use guidata for passing the data around. And yes, you will need to learn how to use structures.
Adam
Adam 2018-9-27
编辑:Adam 2018-9-27
So long as you remember they key line
guidata( hObject, handles )
to write the local handles structure back to the one held in the GUI after you have changed something on the handles structure the rest is very easy. handles is just a structure like any other which just acts like a christmas tree that you can hang whatever you want on. They're ugly for good code, but they have their uses and work for what they do.
(from the link above) actually gives code you can look at showing an example of two apps communicating. I haven't looked at exactly what it shows as I don't use guidata for communicating between GUIDE apps I build, but it should be a simple enough example judging by the image of what it does.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by