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

3 views (last 30 days)
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

Accepted Answer

Jan
Jan on 27 Jun 2012
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
Ben Ferguson
Ben Ferguson on 27 Jun 2012
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.

More Answers (1)

the cyclist
the cyclist on 27 Jun 2012
I think you might find my solution to this question useful: http://www.mathworks.com/matlabcentral/answers/41854-max-in-bin-using-histc

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!