[scilab-Users] Nan indice in min/max

Frederic Jourdin frederic.jourdin at shom.fr
Thu Aug 18 11:31:52 CEST 2011


Hi Serge,
all right I understand (no perfect result exists in this case!).
Then I made such a simple test to get what I need.
Thank you a lot for your answer.
Fred



Serge Steer wrote:
> 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