help-octave
[Top][All Lists]
Advanced

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

Re: uniq -c


From: Geraint Paul Bevan
Subject: Re: uniq -c
Date: Fri, 27 Aug 2004 19:42:35 +0100
User-agent: Mozilla Thunderbird 0.7.1 (X11/20040715)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mike Miller wrote:

| We might consider having a uniq(X) operation that doesn't sort the data.
| We can always do uniq(sort(X)), as in UNIX/Linux.  If uniq operated on
| rows of a matrix, that would work for me, but it would probably be most
| useful with column vectors.
|
| Thanks again.
|
| Mike
|

There is probably a more efficient way and uniq(sort()) would be a bit
pointless with this function, but this will create a unique list and the
put it back into the original order:


function y = uniq (x)
~  [s,i] = sort (x);
~  d = [1, (diff (s) != 0)];
~  y = x (sort (i ((i.*d) != 0)));
endfunction


octave> x = round (5 * rand (1, 10))
x =

~  2  0  4  4  3  3  3  4  5  3

octave> uniq (x)
ans =

~  2  0  4  3  5


- --
Geraint Bevan
http://www.mech.gla.ac.uk/~gbevan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iEYEARECAAYFAkEvgJsACgkQcXV3N50QmNNlYgCePQ1HZpA8NRMuA9QJiAIGoVZR
9PsAmwfdiZolNcr+eDD1DG90nDLSCDqv
=Jbly
-----END PGP SIGNATURE-----



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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