MATLAB Answers

sort the matrix according to order of column

2 views (last 30 days)
ha ha
ha ha on 21 Nov 2018
Edited: ha ha on 10 Apr 2019
Let's say, I have the matrix:
A=[x,y]=[1.1 2;1.2 4;1 4;1.1 3 ;1.3 2;1.3 4;1 2;1.2 3;1.3 3;1.2 2;1 3;1.1 4];
As you observed that:the value of
1st column vary from 1 to 1.3
2nd colume vary from 2 to 4
How can I sort the matrix A to get the result as:
Result=[1 2
1.1 2
1.2 2
1.3 2
1.1 3
1.2 3
1.3 3
1.1 4
1.2 4
1.3 4]

  0 Comments

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 21 Nov 2018
Edited: Guillaume on 21 Nov 2018
Result = sortrows(A, [2 1]) %sort first by 2nd column, then by 1st

  0 Comments

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags