No BSD License  

Highlights from
pauseButton

4.0

4.0 | 3 ratings Rate this file 15 Downloads (last 30 days) File Size: 2.67 KB File ID: #6060
image thumbnail

pauseButton

by Murphy O'Brien

 

16 Oct 2004 (Updated 10 Oct 2006)

Allows user to pause MATLAB simulation.

| Watch this File

File Information
Description

Displays a button which, if clicked, causes MATLAB to pause and ask for an expression to be entered. This expression is evaluated in the calling functions workspace, the result is displayed and then MATLAB continues running its script/simulation.

pauseButton should be called often from inside a loop in a simulation which the user may want to pause. After the first call, it takes almost zero processing time.

Useful if e.g. you are running a long simulation and suddenly decide you want to know how many five card poker hands are in a pack.

Click the pause button, enter nchoosek(52,5) at the command window prompt then press return. Matlab displays
ans =
     2598960
and continues the simulation.

example usage:

for ii=1:50000
   pauseButton;
   for jj=1:1000
     dummy=randn(100)*randn(100);
   end
end

Uses almost no processing time.

MATLAB release MATLAB 7 (R14)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
19 Oct 2004 Tom Robertson  
22 Jul 2005 J Fav

thanks, just what I needed.

06 Apr 2006 tunc ikikardes

Does anyone knows though if there's a way to break pause command from uincontrol buttons. (one can break it by keystrokes that's clear)

10 Dec 2010 Malcolm Hudson  
10 Dec 2010 Malcolm Hudson

Why not just use 'keyboard' instead of input and evalin? That way you can type as many commands as you like before restarting.

07 Dec 2011 Hongxiao Jin

This could be the simplest way to control a loop of images showing, by pausing anywhere, and then check image value and so on:

figure
pause on;
set(gcf,'SelectionType','extend');

for i=1:10000 %your loop
    st=get(gcf,'SelectionType');
    if st(1)=='n'
        pause
    end
    set(gcf,'SelectionType','extend');
    
    %your own scripts, example
    imagesc(randn(100,100))
    drawnow
end

Please login to add a comment or rating.
Updates
22 Oct 2004

Added test for errors in entered user expression, previously an error in this expression would stop the program being paused.

Fixed bug where didn't work if background simulation doesn't update graphics events with drawnow or pause.

10 Oct 2006

Uses the calling functions variable space, allows you to see its variables. Fixed problem where closing it while running caused the calling function error. Now handle invisible so plotting wont plot to the button. Changed title to pause button.

Tag Activity for this File
Tag Applied By Date/Time
pause Murphy O'Brien 22 Oct 2008 07:33:12
wait Murphy O'Brien 22 Oct 2008 07:33:12
button Murphy O'Brien 22 Oct 2008 07:33:12
interrupt Murphy O'Brien 22 Oct 2008 07:33:12
miscellaneous Murphy O'Brien 22 Oct 2008 07:33:12

Contact us at files@mathworks.com