MATLAB: How to Stop an M File

exitm-file

I have several functions in an M File:
function myfun1
myfun2
end
function myfun2
myfun3
end
How can I stop executing a specific function and exit the script?

Best Answer

Hello,
You can use return in your script and function to exit.
For example,
function output = blah(input)
if input == 5
output = 1;
return
end
...
end
With a script:
...
output = blah(input)
if output == 1
return
end
...
So in summary, you can use return just as you might in a function.
Hope this helps!
Related Question