GUIDE - How to use variables that are calculated in Button 1, in Button 2?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Adam
on 26 Sep 2018
This gives various different methods and examples. I use the guidata approach if I am using a GUIDE GUI.
3 Comments
Stephen23
on 27 Sep 2018
Edited: Stephen23
on 27 Sep 2018
"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
on 27 Sep 2018
Edited: Adam
on 27 Sep 2018
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.
More Answers (0)
See Also
Categories
Find more on Migrate GUIDE Apps in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!