How to halt a script launched with 'run' in Matlab / GNU Octave?

2k Views Asked by At

Is there any way to stop a script launched with 'run' or 'source' from Matlab / GNU Octave? I mean different from Ctrl-C, say that a given condition (perhaps given by global variables) holds and a break signal is sent to it.

Example:

The script haltable.m is to be stopped when the environment variable takes a value higher than 0.5.

global environment

while (true)
  environment = rand;
endwhile

It is launched with

global environment

run ('haltable.m')

Where (outside of haltable.m, of course) could it be specified that it must halt after the condition is met?

1

There are 1 best solutions below

2
On BEST ANSWER

It is not possible to implement such a stop condition outside the script, matlab is single threaded and nothing outside is executed. Maybe a conditional breakpoint is what you are looking for.

dbstop in haltable at 5 if (environment>.5)

You have to replace 5 with the correct line number. This does not stop the script but halts it and switches to the debugger.