Is There A Method For Filtering Array Data Based On 2 Values?

2 Ansichten (letzte 30 Tage)
Brad
Brad am 8 Jul. 2013
I’ve got a < 12 x 2 double > array that looks like this;
58570 1
58571 1
58572 1
58573 2
58574 2
58575 7
58576 7
58577 11
58580 11
58581 11
58582 123
58583 123
Column 1 is UTC time, column 2 is a vehicle ID.
I’m looking to filter this data such that the greatest UTC for each vehicle ID is stored in a separate array. Using the above array, the end result would look like this:
58572 1
58574 2
58576 7
58581 11
58583 123
Any ideas on how to accomplish this would be appreciated. Thanks.

Akzeptierte Antwort

Matt J
Matt J am 8 Jul. 2013
[~,idx]=unique(data(:,2),'last');
data=data(idx,:);
  1 Kommentar
Brad
Brad am 8 Jul. 2013
Matt, this runs like a champs and is compact. And I ran RIGHT OVER IT when looking in the documentation.
Thanks for taking a look at this.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by