Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
sorting and finding the position

Subject: sorting and finding the position

From: shanas pr

Date: 27 Nov, 2011 17:34:08

Message: 1 of 5

pls help me


I have a series of data with 5 columns and 100 rows


what i wan to do is .....to find the maximum value of a specific column let us say 5th column and to print the entire row which contain the maximum value (at column 5)????


and to repeat the procedure for1000s of rows plz do help



for example>>>>>

                                    1 2 3 4
                                    6 4 5 9
                                    2 6 8 0


i want to check which is the max value in 4th column? answer will be 9
then i need to print the 2nd row ie.6 4 5 9???



thanks in advance...

Subject: sorting and finding the position

From: Rune Allnor

Date: 27 Nov, 2011 17:38:30

Message: 2 of 5

On 27 Nov, 18:34, "shanas pr" <shana...@gmail.com> wrote:
> pls help me
>
> I have a series of data with 5 columns and 100 rows
>
> what i wan to do is .....to find the maximum value of a specific column let us say 5th column and to print the entire row which contain the maximum value (at column 5)????
>
> and to repeat the procedure for1000s of rows plz do help
>
> for example>>>>>
>
>                                     1 2 3 4
>                                     6 4 5 9
>                                     2 6 8 0
>
> i want to check which is the max value in 4th column?    answer will be 9
> then i need to print the 2nd row ie.6 4 5 9???
>
> thanks in advance...

idx = find (x(:,4)==max(:,4));
x(idx,:)

Rune

Subject: sorting and finding the position

From: Nasser M. Abbasi

Date: 27 Nov, 2011 18:23:57

Message: 3 of 5

On 11/27/2011 11:38 AM, Rune Allnor wrote:
> On 27 Nov, 18:34, "shanas pr"<shana...@gmail.com> wrote:
>> pls help me
>>
>> I have a series of data with 5 columns and 100 rows
>>
>> what i wan to do is .....to find the maximum value of a specific column let us
>say 5th column and to print the entire row which contain the maximum value (at column 5)????
>>
>> and to repeat the procedure for1000s of rows plz do help
>>
>> for example>>>>>
>>
>> 1 2 3 4
>> 6 4 5 9
>> 2 6 8 0
>>
>> i want to check which is the max value in 4th column? answer will be 9
>> then i need to print the 2nd row ie.6 4 5 9???
>>
>> thanks in advance...
>

> idx = find (x(:,4)==max(:,4));
> x(idx,:)
>
> Rune

another possibility is the use of the second output
argument to max:

----------------------
[v,I]=max(A(:,4))
A(I,:)

ans =

      6 4 5 9

---------------------

--Nasser

Subject: sorting and finding the position

From: Roger Stafford

Date: 27 Nov, 2011 18:27:08

Message: 4 of 5

"shanas pr" <shanaspr@gmail.com> wrote in message <jatsag$q6d$1@newscl01ah.mathworks.com>...
> I have a series of data with 5 columns and 100 rows
> what i wan to do is .....to find the maximum value of a specific column let us say 5th column and to print the entire row which contain the maximum value (at column 5)????
> and to repeat the procedure for1000s of rows plz do help
- - - - - - - -
  Let c be a vector containing column numbers to be tested and A the data matrix in question.

 [~,p] = max(A(:,c),1);
 x(p,:) % <--- Or use fprintf to print these

Roger Stafford

Subject: sorting and finding the position

From: Roger Stafford

Date: 27 Nov, 2011 18:40:09

Message: 5 of 5

"Roger Stafford" wrote in message <jatvds$5fb$1@newscl01ah.mathworks.com>...
> [~,p] = max(A(:,c),1);
> x(p,:) % <--- Or use fprintf to print these
- - - - - - - -
  Whoops!

 [~,p] = max(A(:,c),1);
 A(p,:) % <--- Or use fprintf to print these

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us