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 ret
Yes you can with the help of
return;
Return works in Matlab-scripts like it does in functions.
e.g.
function [ point ] = PointDoubling( x,y,p,a )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
if y==0
point='Not calculated';
return;
end
a2=(3*(x^2))+a;
b2=(2*y);
i=1;
while 1
if mod(b2*i,p)==1
break;
end
i=i+1;
end
s=mod(a2*i,p);
x1=mod(((s^2)-(2*x)),p);
y1=mod(((-y)+(s*(x-x1))),p);
point=[x1,y1];
end
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