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

11 Ansichten (letzte 30 Tage)
monmatlab
monmatlab am 3 Jan. 2017
Kommentiert: Guillaume am 5 Jan. 2017
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

Akzeptierte Antwort

monmatlab
monmatlab am 3 Jan. 2017
I got around it using the timer function
t = timer('TimerFcn',@(x,y)imshow('IMAGE'),'StartDelay',3);
start(t)
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
handles.figure=figure;
figure(handles.figure)
but still it does not help, does someone have a solution? thank you!

Weitere Antworten (2)

Image Analyst
Image Analyst am 3 Jan. 2017
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
Guillaume am 3 Jan. 2017
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 Kommentare
monmatlab
monmatlab am 5 Jan. 2017
it worked actually using the timer and for the other problem regarding imshow, i just learned that imshow plots in the most current figure so to avoid this you could do it like this:
ax= subplot(3,3,indexa(handles.i))
imshow(handles.image);
t = timer('TimerFcn',@(x,y) *imshow('white.png','Parent',ax)*,'StartDelay',1);
start(t)
Guillaume
Guillaume am 5 Jan. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by