Clear Filters
Clear Filters

Why there is a difference between sortrows(A) and sortrows(A,1)?

3 views (last 30 days)
Hello all
I was wondering why there is difference between A=sortrows(A) and B=sortrows(A,1), denote that A is n by n matrix?
According to matlab documentation sortrows(A), sort the rows of a matrix in ascending order based on the elements in the first column. So I guess it should result in the same output as sortrows(A,1) which according to matlab, sorts A based on the columns specified in the vector column.
But when I look at the 5 first varaibles in A and B, I see different indexes.
index a=[7 10 17 35 41]
index b=[306 741 859 311 740]
What s happening?

Answers (1)

madhan ravi
madhan ravi on 2 Jun 2020
I get the same results?
>> Matrix
Matrix =
1 1 4 2
4 4 4 5
2 2 3 1
3 4 1 5
>> B = sortrows(A)
B =
1 1 4 2
2 2 3 1
3 4 1 5
4 4 4 5
>> C = sortrows(A,1)
C =
1 1 4 2
2 2 3 1
3 4 1 5
4 4 4 5
>>

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!