Can a Matlab M-script be stopped by a statement in the script?

后端 未结 3 493
误落风尘
误落风尘 2021-02-05 06:17

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

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 06:41

    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
    

提交回复
热议问题