[scilab-Users] Nan indice in min/max

Serge Steer Serge.Steer at inria.fr
Thu Aug 18 11:09:32 CEST 2011


Le 18/08/2011 09:23, Frederic Jourdin a écrit :
> Hi all,
> if I run this:
>
> [m, k]=min([ %nan %nan %nan])
> k  =
>    1. m  =
>    Nan
>
> The result for m is correct but seems incorrect
> for k. Is it ? (I am expecting Nan instead).
>
> Thanks
> Fred
> Scilab 5.3.0 on Linux
>
>
min help page says that k is the index that realize the min first.
So the question is more about the semantic of the min function in such a
case than the return value for k:
should it
- throw an error
- return k=[] and m=[] (but it is the answer for min([])
In any case all solutions will require a test after the min evaluation
to decide what is the situation. So it is probably better to make the
test before:

if and(isnan(x)) then
   //do what you want here
else   
  [m, k]=min(x)
 end

Serge Steer
INRIA

PS: note that, at least, the Scilab behavior here is coherent with the
Matlab one.
>> [m, k]=min([ nan nan nan])

m =

   NaN


k =

     1




More information about the users mailing list