A mix of sorting, unique and deleting bits of an array

I have an array of frequencies (1st column) and their amplitudes (2nd column).
Each entry has a different amplitude, but there are several occurrences of each frequency.
I want to be able to use the highest amplitude of each frequency. Just ignoring or deleting the rest.
Ive tried using the unique rows function, and this sorts them all so that similar frequencies are together with the highest amplitude one first, but how would i go about deleting the lower amplitude ones.
Thanks

1 Comment

Solutions would be easier to test, if you provide some test data.

Sign in to comment.

 Accepted Answer

Y = sortrows(X);
[uniqY, index] = unique(Y(:, 1), 'last');
Now Y(index, :) contains the largest values in the 2nd column.
The order of the results might change in the future, see Answers: Change of set functions in the future. Unfortunately a workaround can be required to ensure a specific order.

1 Comment

It worked nicely. The only thing i had to change was that for some reason the sortrows function put the amplitude of the common frequencies in descending order. So i used 'first' in the unique function and it worked!
cheers

Sign in to comment.

Categories

Tags

Asked:

on 27 Jun 2012

Community Treasure Hunt

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

Start Hunting!