Breaking from for loop in MATLAB GUI

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-12-23T21:02:06Z Indexed on 2010/12/25 3:54 UTC
Read the original article Hit count: 194

Filed under:
|

I have a for loop in the opening function of a GUI in MATLAB and I'm trying to use a callback button to break the loop. I'm new to MATLAB. Here's the code I have:

%In the opening function of the GUI
handles.stop_now = 0;
for i=1:inf
   if handles.stop_now==1
      break;
   end
end


% Executes on button press 
function pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to end_segmenting_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.stop_now=1;
guidata(hObject, handles);

For some reason, despite defining the variables with handles, the loop doesn't break upon pressing the button. Anyone know what's going on? Thanks.

© Stack Overflow or respective owner

Related posts about gui

Related posts about matlab