help-octave
[Top][All Lists]
Advanced

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

Re: Using the unique command without sorting the values and getting the


From: Nicholas Jankowski
Subject: Re: Using the unique command without sorting the values and getting the rows
Date: Wed, 15 Jun 2016 09:54:25 -0400

On Tue, Jun 14, 2016 at 7:49 PM, RT <address@hidden> wrote:
Greetings

I'm trying to get all the rows based on the unique values found in the second column.  see example below
The index of the rows that I would keep would be row 1,2,3,5,7 (in that order)
I was thinking of using unique([5 5 3 4],'stable') (the 'stable' option seems to keep the
index value order without sorting), but octave 4 doesn't have the stable option how can a work around this


I'm not certain about how to use unique to select based on column 3, but will your column 3 repeats always be consecutive? Is the data fixed precision as shown, or are they floating point values such that such that C(3,3)==C(4,3) would give false?

manual ways of approaching this without unique:
If they are fixed precision and always consecutive, you could use diff on column 3 and trim out locations where diff==0 using find.

if they are not always consecutive, but still fixed precision, sort them according to column 3, then trim as above, then resort them back to original order using the column 1 index. There may be a more elegant way to go about this, but even with hundreds of rows the performance shouldn't be horrible. 


reply via email to

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