How to nest callback into while loop?
11 views (last 30 days)
Show older comments
Sergey Lopatnikov on 11 Oct 2021
Commented: Sergey Lopatnikov on 13 Oct 2021
I write simple program with a while loop
Within the while loop in each cicle the figure with two buttons: "CONTINUE" and 'FINISH' created.
As expected, if one preses the CONTINUE button, the cicle repeats, in case of presing FINISH, the while loop is finishing.
The problem is that if callback functions for button place within the "while" loop the MATLAB says that callback function(s) is incorrectly nestled.
If callback functions for button place outside the "while" loop, after pressing one of the buttons the MATLAB says that 'event_data' in callback function is not recognized.
function [TGA] = TGA_MULTY_LOAD()
Geoff Hayes on 13 Oct 2021
@Sergey Lopatnikov - the _'event_data' in callback function is not recognized_ error message makes sense since you are trying to use a variable doesn't exist. To avoid this error, just pass an empty array into the callback
But is this really what you want to do? After the call to uiwait, you call both the continue and finish callbacks
So which one should be called? Also, since you have already pushed a button, either Continue or Finish, then one of those callbacks will already fire. I think that you can remove these two lines altogether and just keep the
which will wait until the GUI closes (which you do in both the callbacks).
As an aside,do you want to close the GUI if the user continues? Why not re-use the same GUI for each iteration of the while loop (this would mean you would need to create the GUI outside of the loop)?
More Answers (0)
Find more on Interactive Control and Callbacks 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!