MATLAB: How to sort a matrix based on two columns

arrayMATLABmatrixsort

Assume matrix A as follows:
A = [
1 1 20
1 2 32
1 3 10
2 1 45
2 2 10
2 3 15
3 1 43
3 2 90
];
I want to sort matrix A based on the third column. However, I want to keep the first column also sorted. Whenever the ID changed, then column 3 is sorted. The output should be something likes:
B = [
1 3 10
1 1 20
1 2 32
2 2 10
2 3 15
2 1 45
3 1 43
3 2 90
];

Best Answer

>> sortrows(A,[1 3 2]) % doc sortrows for details...
ans =
1 3 10
1 1 20
1 2 32
2 2 10
2 3 15
2 1 45
3 1 43
3 2 90
>>