A very simple, and perhaps obvious, question: How can I abort execution of a Matlab M-script using a statement within the script?
This is analogous to calling return
in the middle of a function to end it immediately.
To stop execution of a MATLAB® command, press Ctrl+C or Ctrl+Break.
Typing pause(inf) puts you into an infinite loop. To return to the MATLAB prompt, type Ctrl+C. Example: pause(3) pauses for 3 seconds. Example: pause(5/1000) pauses for 5 milliseconds.
Use end to terminate the function.
exit terminates the current session of MATLAB®.
If return
is not want you need, I think you want to use break
break terminates the execution of a Matlab code. For example, statements in the loop that appear after the break statement are not executed.
In nested loops, break exits only from the loop in which it occurs. Control passes to the statement that follows the end of that loop.
As of Matlab R2015b break
can no longer be used to pre-terminate a script. A break
can now only be used to a for-loop. The code will not run and an error will be thrown. This was technically always true, but it is now enforced.
The proper way is to use return
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With