How to pause just one function, while others keep running?
Mostra commenti meno recenti
I have a GUI with two plots, one is controlled by a button, that when it is pressed it shows an image for a certain amount of time before it changes to another one, for this purpose a pause is implemented. The other plot shows real-time data from the Arduino. Unfortunately, the pause of the first plot, causes the streaming also to stop.
I tried to separate them by generating for each plot a GUI, same problem occurred, and plotting was totally messed up, since the pictures and the graphs were overlapping in one GUI and some times in the other one.
Is there a possibility to make the pause just affects one function, while the other one keeps running? Thank you
Risposta accettata
Più risposte (2)
Image Analyst
il 3 Gen 2017
1 voto
You can have a checkbox. One function checks the checkbox. If it's checked, then it basically skips to the end of the function, meaning it doesn't do anything (it's paused) until the checkbox is unchecked.
Guillaume
il 3 Gen 2017
1 voto
Fundamentally, what you are asking cannot be done in matlab (unless maybe if you use the parallel processing toolbox). At the m file level, Matlab is single threaded so only one function can execute at a time. Meaning that if your code is busy plotting something, it can't read data from a stream at the same time.
Now indeed, you can sort of simulate multithreading with timers as long as the timer function does not take too long, but while the timer is executing no other m file function is running.
2 Commenti
monmatlab
il 5 Gen 2017
Guillaume
il 5 Gen 2017
Yes, as I said you can sort of simulate multithreading with timers. It will work most of the time, however you should expect some subtle bugs to occur if your machine is under heavy load. If for some reason, the imshow takes too long, then your real time streaming may break.
By the way,
t = timer('TimerFcn',@(~,~) imshow('white.png','Parent',ax),'StartDelay',1);
would be slightly cleaner.
Categorie
Scopri di più su Creating, Deleting, and Querying Graphics Objects in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!