Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function myvar = myfunc()
- myvar = true;
- h_fig = figure;
- % create a useless button
- uicontrol( h_fig, 'style', 'pushbutton', ...
- 'string', 'clickme', ...
- 'callback', 'myvar = false' );
- % wait for the button to be pressed
- while myvar
- pause( 0.2 );
- end
- close( h_fig );
- disp( 'this will never be displayed' );
- end
- function make_useless_button()
- % Initialize variables and graphics:
- iCounter = 0;
- hFigure = figure;
- hButton = uicontrol('Style','pushbutton','Parent',hFigure,...
- 'String','Blah','Callback',@increment);
- function increment(source,event)
- iCounter = iCounter+1;
- disp(iCounter);
- end
- end
- function make_stop_button()
- % Initialize variables and graphics:
- keepLooping = true;
- hFigure = figure;
- hButton = uicontrol('Style','pushbutton','Parent',hFigure,...
- 'String','Stop','Callback',@stop_fcn);
- % Keep looping until button is pressed:
- while keepLooping,
- drawnow;
- end
- % Delete figure:
- delete(hFigure);
- % Nested callback:
- function stop_fcn(source,event)
- keepLooping = false;
- end
- end
- function myfunc()
- h_fig = figure;
- % add continue_loop to the GUI-handles structure
- fig_handles = guihandles( h_fig );
- fig_handles.continue_loop = true;
- guidata( h_fig, fig_handles );
- % create a useless button
- uicontrol( h_fig, 'style', 'pushbutton', ...
- 'string', 'clickme', ...
- 'callback', @gui_callback );
- % wait for the button to be pressed
- while fig_handles.continue_loop
- fig_handles = guidata( h_fig ); % update handles
- pause( 0.2 );
- end
- close( h_fig );
- disp( 'callback ran successfully' );
- end
- % The arguments are the Matlab-defaults for GUI-callbacks.
- function gui_callback( hObject, eventdata, handles )
- % modify and save handles-Structure
- handles.continue_loop = false;
- guidata( hObject, handles );
- end
Add Comment
Please, Sign In to add comment