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:
Searching for list of maximum values in a matrix along the two dimensions

Subject: Searching for list of maximum values in a matrix along the two dimensions

From: Camille Couzi

Date: 29 Oct, 2010 20:00:07

Message: 1 of 4

Hi matlabers!

I am trying to get the maximum values of one matrix along the two dims,.
I have been looking at max and sort functions, but I need the matrix sorted in the two dimensions, and if possible getting the indexes of the values.

Fo example, I would need to get this matrix sorted:
A=[60 25 3 4;6 45 85 2;1 52 7 95];

And would like to get as result a column matrix like that:
A_sorted=[95;85; 60; 52 ;45 ;25; 7 ;6; 4; 3; 2; 1];
and a matrix with the indexes of the values of A in order:
inedx_A=[3 4;3 3; 1 1;3 2;2 2;1 2 ...

Somebody has an idea...?!!!

Thanks in advance...

Camille

Subject: Searching for list of maximum values in a matrix along the two dimensions

From: Jan Simon

Date: 29 Oct, 2010 20:13:04

Message: 2 of 4

Dear Camille,

A = [60 25 3 4;6 45 85 2;1 52 7 95];
[A_sorted, Index] = sort(A(:));
[a, b] = ind2sub([3,3], Index);
index_A = [a, b];
 
Jan

Subject: Searching for list of maximum values in a matrix along the two dimensions

From: Camille Couzi

Date: 29 Oct, 2010 20:41:05

Message: 3 of 4

Thanks you very much Jan!!!!!!!
That's fabulous!!!!!!!!!!!! thanks you a lot!!! :-)

Subject: Searching for list of maximum values in a matrix along the two dimensions

From: Jan Simon

Date: 29 Oct, 2010 21:21:04

Message: 4 of 4

Dear Camille,

you are welcome! I forward the thanks to the Matlab designers:
I imagine solving this tiny problem in C. Of course, this is not a fair comparison, but it gives an impression why I like developing software with Matlab.

Jan

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