From: Ahmed Hussain on
Hello,

I have an array with 2 columns and several rows and looks like the following:

Frequency Voltage
300 -10.5
301 -10.8
302 -10.0
303 -8.0
304 -11.2
...... ........ goes on.........

How can I find the first 50 max values from the voltage column and its coressponding index to get the frequency as well.

Thank you,

Ahmed H
CTH-Sweden
From: us on
"Ahmed Hussain" <ahmedhussain85(a)yahoo.com> wrote in message <hp0h44$pj9$1(a)fred.mathworks.com>...
> Hello,
>
> I have an array with 2 columns and several rows and looks like the following:
>
> Frequency Voltage
> 300 -10.5
> 301 -10.8
> 302 -10.0
> 303 -8.0
> 304 -11.2
> ..... ........ goes on.........
>
> How can I find the first 50 max values from the voltage column and its coressponding index to get the frequency as well.
>
> Thank you,
>
> Ahmed H
> CTH-Sweden

one of the many solutions

nm=3; % <- # max
m=[
1 1
2 5
3 6
4 2
6 10
2 1
-1 8
];
ms=sortrows(m,2);
ms=ms(end-nm+1:end,:)
%{
% ms =
3 6
-1 8
6 10
%}

us
From: Nathan Greco on
"Ahmed Hussain" <ahmedhussain85(a)yahoo.com> wrote in message <hp0h44$pj9$1(a)fred.mathworks.com>...
> Hello,
>
> I have an array with 2 columns and several rows and looks like the following:
>
> Frequency Voltage
> 300 -10.5
> 301 -10.8
> 302 -10.0
> 303 -8.0
> 304 -11.2
> ..... ........ goes on.........
>
> How can I find the first 50 max values from the voltage column and its coressponding index to get the frequency as well.
>
> Thank you,
>
> Ahmed H
> CTH-Sweden

doc sort

Notice the second optional output.

Assume X is your two columned matrix:

[Y,ix] = sort(X(:,2),'descend');
%Y is the sorted voltage values max to min
%ix are the corresponding index values that you can relate to frequency

Y(1:50) %is the 50 first max values
X(ix(1:50),1) %is the 50 corresponding frequency values

I hope that helps

-Nathan