1

I am fairly new to MatLab GUI building and I have a "continue" button in the GUI.

So basically, at some point in my program, the program has to wait for the user to click on the "continue" button to keep going.

The only way I can think of doing this is to make the program loop infinitely in a while loop until the button is clicked and it exits the loop. This does not seem to work.

So the loop is as follows:

while (get(handles.continue,'value')) == 0 
    disp('in the loop')
    guidata(hObject,handles);
end

However, it is not exiting the loop. I tried changing the button from a pushbutton to a togglebutton but it would not exit the loop.

I know it is not the most efficient way to make the program wait but can anyone tell me why it is not exiting that loop or suggest a more efficient way?

Jason Sundram
  • 12,225
  • 19
  • 71
  • 86
Ali P
  • 519
  • 6
  • 21
  • 3
    It seems you have same problem as [here](http://stackoverflow.com/questions/4522447/breaking-from-for-loop-in-matlab-gui?rq=1). See accepted answer. – Danil Asotsky Jun 04 '13 at 18:49

1 Answers1

1

The right way to do this is to write a callback associated with the Continue button:

set(handles.continue, 'Callback', @continueProcessing);

Then, write the continueProcessing function to do whatever it is that you need to do after the user pushes the button. A prototype is below:

function continueProcessing(hObj, event)
    ...
end

continueProcessing() will run whenever the button is pushed. Note that callbacks in MATLAB must have the first two arguments be hObj (the handle of the component whose callback is now being called) and eventdata.

Dang Khoa
  • 5,693
  • 8
  • 51
  • 80