How to pause just one function, while others keep running?

조회 수: 8(최근 30일)
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

채택된 답변

monmatlab 2017년 1월 3일
I got around it using the timer function
t = timer('TimerFcn',@(x,y)imshow('IMAGE'),'StartDelay',3);
the problem that is still remaining is the figure instability, one part is plotted one another figure while another part is not shown at all. I even use the handles function
but still it does not help, does someone have a solution? thank you!

추가 답변(2개)

Image Analyst
Image Analyst 2017년 1월 3일
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 2017년 1월 3일
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
Guillaume 2017년 1월 5일
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.

댓글을 달려면 로그인하십시오.


Find more on Specifying Target for Graphics Output 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!

Translated by