MATLAB Answers

Continuous slider callback, not updated handles in callback function.

5 views (last 30 days)
I am writing a program with several gui's/windows using tabs. Therefore are all handles accessible from tha main gui/window. My addlistener is placed in a gui's (not the main gui) openingFcn where i have handles from the main gui as input argument. After addlistener is used i am adding more variables in my handles and these variables are not in handles in my continuous callback function. Why is that and is there an easy solution? Or should i try and use addlistener later in the program (can't think of a clean way to do this) when all variables have been added to handles.


Sign in to comment.

Accepted Answer

Adam on 29 Jun 2016
Passing handles around is not a good idea because it is passed by value, so as you have seen, anything added after does not come through.
You can pass the hObject of the GUI around instead and then use
handles = guidata( hObject );
I would never recommend having GUIs have such access to each other in general, but the alternative I use is too in-depth to explain if you are not familiar with Matlab OOP. I pass class objects between UIs instead and attach listeners to those. I never want a GUI listening to another GUI, I would much rather have one GUI update the properties of a shared object and another GUI listen to that shared object. It is far more robust and less prone to bugs also. But if you have never done Matlab OOP it takes more explaining than I have time for right now.

  1 Comment

Joakim Magnusson
Joakim Magnusson on 30 Jun 2016
I was new with matlab when i began writing this code and now i think it's to big to change it. But thanks for the input! Had forgotten about guidata, that made the trick.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!