Why does Matlab not allow you to interupt a function mid execution?

This is more a question directed towards the mathworks staff.
Why does MATLAB not let you interupt execution to see the variable values/ variables in scope etc.
I am familiar with the pause.m function, however this needs to be called from the command line and can not be called from the GUI.
in MS Visual Studio you can pause from the IDE and then start again. This is an excellent feature of the IDE.
Are there any plans to include a button on the IDE to do this?

Answers (2)

Jason Ross
Jason Ross on 13 Feb 2013
Edited: Jason Ross on 13 Feb 2013
If you set a breakpoint in a function the debugger will stop there and you can inspect variables. You can also step in a variety of ways (step, step in, continue execution, etc).
The example provided in the blog post just seems to be encoding your own custom breakpoint mechanism that is available at runtime. It's not uncommon to use such constructs in a language to enable higher logging levels based on either a file (as in the example) or the setting of an environment variable. You can certainly do this in MATLAB jsut as you would any other programming language that can read the filesystem or check the value of environment variables. What you do when you hit that breakpoint is up to you -- continue execution, log a diagnostic message, output something to the screen, etc.

4 Comments

There is nothing in MATLAB, like control-break in Visual Studio. If your program is merrily crunching away in VS, with no breakpoints or anything, then when you type control-break, it will immediately stop what it's doing and position you in the code at the next line of code that it was going to execute (before you interrupted it). MATLAB does not have this capability, and requires more planning on when and where you hope to break at.
A related nice feature would be to be able to grab the arrow and move it to another line of code that you want to execute instead of the one it's pointing to, for example skip the next block of code or re-execute that function that you just got out of. Visual Basic has this - would be absolutely fantastic and a great help if MATLAB did too.
but breakpoints need to be set prior to starting execution...
The bits of example provided in that blog are what is built into Visual Studio.
Thanks for the clarification -- the example provided seemed to be more intrusive than just setting a breakpoint and also required planning on where to put the code in place.
I see. I'd suggest you add in something that writes to a log that you can check to see how things are progressing without stopping execution.
(just to be clear -- although I am "MathWorks Staff", I'm writing this advice as "myself")

Sign in to comment.

You can use ctrl+c to stop some things but not all. See this solution:

5 Comments

I work with big data sets and when I start processing I might expect 24hrs of run-time. When I come back in 36hrs and see the run still has not finished I face the choice of Ctrl+C and killing the run, or letting it continue.
The problem is I dont know if the run is taking longer than I expected due to some unexpected behaviour by MATLAB/ poor coding by me, or is just about to finish (in which case I really dont want to Ctl+C).
would be so helpful just to be able to look at the values of the variables and then continue the run.
You can print stuff out to the command line, say every 1000th iteration, or better yet, use a progress bar and a static text control on your GUI.
I'd really suggest you add some logging code so that you don't have to wonder. Logging can be very verbose (exporting the values, etc), or be very basic and say something like "I'm still alive", or report progress every n iterations.
Logging code or a waitbar with useful percentages and messages.
I do use these features (eg. http://www.mathworks.co.uk/matlabcentral/fileexchange/28067-text-progress-bar which is excellent) and logging.
All of them dont even come close in my mind to the flexibility that the "pause" button the VS IDE gives.

Sign in to comment.

Categories

Find more on App Building in Help Center and File Exchange

Tags

Asked:

on 13 Feb 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!