A mix of sorting, unique and deleting bits of an array
3 views (last 30 days)
Show older comments
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
Accepted Answer
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.
More Answers (1)
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
0 Comments
See Also
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!