octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Cell arrays of strings in "sort" and "unique"


From: Alois Schloegl
Subject: Re: Cell arrays of strings in "sort" and "unique"
Date: Wed, 15 Sep 2004 19:18:39 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax)



David Bateman wrote:

According to Quentin Spencer <address@hidden> (on 09/15/04):
Output from MATLAB R14:



x = [Inf, NaN, -Inf, 3, 2, 1];
[a, ai] = sort (x, 'ascend')
a =

-Inf     1     2     3   Inf   NaN


ai =

   3     6     5     4     1     2

[a, ai] = sort (x, 'descend')
a =

 NaN   Inf     3     2     1  -Inf


ai =

   2     1     4     5     6     3


Now this isn't what I would have expected. I'd assumed that the NaN's
were always sorted to the end. It seems that matlab always does an
ascending sort and then a flip(lr|ud) or whatever... It might in fact
be faster this way, but the advantage of always sorting the NaN's
to the end would be that it is easier to drop them...

For compatiability we shoudl probably do the same thing...

In this case, compatibility is not a "must". The result might differ already in the next version of matlab. If the position of NaN is important, its recommended doing explicit checks for NaN's - and if only for the sake of readibility of the code.

- just my 2c -


 Alois




reply via email to

[Prev in Thread] Current Thread [Next in Thread]