MATLAB: Code execution in GUI

callbackguiguideMATLABplot

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?
Thanks

Best Answer

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.