Code execution in GUI
1 view (last 30 days)
Show older comments
Vittorio on 27 Jun 2018
Commented: OCDER on 28 Jun 2018
I am trying to build my first GUI. I have what I think is a very dumb question. The GUI has a button that, when pressed, asks the user to select a file (using uigetfile). The program reads data from the file and updates a popup menu with information contained in the selected file. I have done this without problem inside the button callback function and it works.
After this, the program is essentially supposed to enter an infinite loop, where it keeps reading data from the selected file and updating a plot with them. The data used for the plot change based on the user selection in the popup menu. Therefore I need to both keep plotting and be able to catch the popup selection change.
I simply don't know where to put the plotting code. I can't put it in the button callback function, otherwise I won't be able to process the popup callback. For the same reason I can't put it in the popup callback (I'd catch the first selection change in the popup but none after that). So, where am I supposed to put the plotting code?
OCDER on 27 Jun 2018
You could use a timer object to run the plots in the background until it receives a stop signal. See the example code and fig as a starting point. It'll draw something forever and changing something in the listbox will alter the plots in real time.
OCDER on 28 Jun 2018
You're welcome! Note that this is still a workaround solution as matlab GUI doesn't work well with situations that should use multiple threads - one thread for plotting and one thread for detecting changes to your GUI. Maybe it changed in the newer versions. Read this:
More Answers (1)
Rik on 27 Jun 2018
What you could do is something like the following:
'Position',[0.25 0.25 .5 .5],...
%set an interuptor
%get the data with uigetfile etc (you might need a uiwait in here)
%run the looper
%reload the handles to see if the interuptor was set
%figure was closed
%put your loop code here
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!