[Scilab-users] Start an arrested loop with one keystroke only

Rafael Guerra jrafaelbguerra at hotmail.com
Tue Nov 22 17:44:18 CET 2016


Hi Jens,

I like the idea of using a function but could not find out right way how to simplify and generalize yours for arbitrary loops.

If instead of using a function, we copy the following line into "any" for or while loop we will get the same result as in your particular example:

// START OF CODE
clf;
x=0:1;
for i=1:10
   plot(x,i*x)
   b=xclick(); if b(1)==4 then abort elseif b(1)==5 then break end  //copy this inside any while/for loops
end
// END OF CODE

Regards,
Rafael

From: users [mailto:users-bounces at lists.scilab.org] On Behalf Of Jens
Sent: Tuesday, November 22, 2016 4:27 PM
To: users at lists.scilab.org
Subject: Re: [Scilab-users] Start an arrested loop with one keystroke only

Hallo Tim,
I have answered my  last question by 'while' instead of 'for':

function k=stopgoclick(k, n)//control a figure loop by mouseclicks

        //INPUT

        //k: figure loop counter

        //n: length of figure loop

        //left mouse click: continue loop i. e. next figure  (b(1)=3)

        //middle mouse click: abort script  (b(1)=4)

        //right mouse click: break loop (b(1)=5)

        //OUTPUT

        //k; n after right mouse click to break loop,  else: k from input

        //Example: i=1; while i<=n; plot(x,i*x); i=stopgoclick(i,n);  i=i+1; end

        b=xclick()

        if b(1)==3//left mouse: next image

           return

       elseif b(1)==4//middle mouse: end script

           abort

       elseif b(1)==5//break loop

           k=n+1

        end

endfunction



    x=0:1;

    n=10;

    i=1;

while i<=n

    plot(x,i*x)

    i=stopgoclick(i,n);

    i=i+1;

end

'further commands'




I am satisfied with the function. Please advise if a simpler solution exists.
Cheers
Jens


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20161122/ebf4aced/attachment.htm>


More information about the users mailing list