user1132254
user1132254

Reputation: 141

Pause while loop and do something else in Matlab

I created a GUI in Matlab and one of the buttons the user supposed to press at the beginning has a while loop in it. I am taking frames one by one in this while loop. My problem is that I want the user to be able to pause this process (not to stop completely), so I added a pause button and I am changing a flag as this button is pressed. I need to put a code inside this matlab that will pause the loop procedure as pause button is pressed once, and will continue to the loop process when pause button is pressed again. I tried

if flag==1 
   pause on; 
else 
   pause off 
end;

But I saw that "pause on;" does not pause a while loop. Is there a function or method that I can use? In addition, I want other buttons to be able to work when code is in pause mode; for example another button displays some words, so when in pause mode, if this display words button is pressed, it must display the words on screen. I tried using "waitfor" but it stopped everything and this display button didn't work. I would appreciate any kind of help.

Upvotes: 0

Views: 3879

Answers (2)

Dennis Jaheruddin
Dennis Jaheruddin

Reputation: 21561

I think this may be what you are looking for

while flag == 1
   % Get/process your user input here

   % Finish checking user input
   pause(1) %Check every second, can of course be reduced
end

Upvotes: 0

Edric
Edric

Reputation: 25160

You probably want to use MATLAB's WAITFOR function to do this.

Upvotes: 1

Related Questions