[Scilab-users] Invalid Index error when using for and select

Dang, Christophe Christophe.Dang at sidel.com
Mon May 13 09:19:26 CEST 2013


Hello, 

De la part de MattM
Envoyé : mardi 7 mai 2013 18:35

> for t=0:1:15
>     select t
>     case 0
>         B(0)=0
>     else
>         B(t) = abs(besselj(q,q.*1/15*t)/(q.*1/15*t));
>     end
> end

In addition to Mathieu's answer,

your code performs 16 times a test for only one value.

Additionally, Scilab performs severals tests when applying a function
or performing an operation,
the reason why it is more efficient to use matrices, see
http://mailinglists.scilab.org/Scilab-users-Regarding-simple-numerical-operations-result-display-tt4026274.html#a4026307

A probably more efficient code would look like

// **********

t = 0:15;

u = q/15*t(2:$); // computes starting at index 2

B = abs(besselj(q, u)./u);

B = [0, B]; // adds the first point

plot(t, B)

// **********

Not sure this is addapted in your case,
but it seems to give the same values as your code,
and it generates a line vector instead of a column one.

Hope this helps.

-- 
Christophe Dang Ngoc Chan
Mechanical calculation engineer
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error), please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.





More information about the users mailing list