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:
Sort of matrix in the ascending order of column but keeping each row element

Subject: Sort of matrix in the ascending order of column but keeping each row element

From: Danny

Date: 1 Aug, 2011 20:17:31

Message: 1 of 2

I'd like to sort the matrix A into B, in the ascending order of column but keeping each row element as follows :
A=
[1 0 0 0;
1 2 0 0;
1 2 4 0;
1 3 0 0;
1 3 4 0;
1 2 3 4;
1 4 0 0;
1 2 3 0]

B=
[1 0 0 0;
1 2 0 0;
1 2 3 0;
1 2 3 4;
1 2 4 0;
1 3 0 0;
1 3 4 0;
1 4 0 0]

I tried to convert to number to string, sort and back string to number. However, it worked only if the element is 1 digit.

Subject: Sort of matrix in the ascending order of column but keeping each row element

From: Bruno Luong

Date: 1 Aug, 2011 20:23:27

Message: 2 of 2

B = sortrows(A)

%Bruno

Tags for this Thread

No tags are associated with 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