Incorrect output of sortrows function

Hi everyone,
Sortrows function seems to return incorrect arranged array, here is very specfice example.
A = [110.359026830732,-23.6025085449219,2.30662154653535; ...
110.359026830732,-23.6025085449219,2.93833414713542; ...
110.359026830732,-23.6025085449219,2.30662154653535]
In array A, the first and last point is the same and should be returned in position 1 and 2. But point 3 will be returned in position 3. However, output is not correct as below:
B = sortrows(A,[1 2],{'ascend','ascend'})
>> B =
110.3590 -23.6025 2.3066
110.3590 -23.6025 2.9383
110.3590 -23.6025 2.3066
Checking if the rows 1 and 3 are same:
A(1,:) == A(3,:)
ans =
1×3 logical array
1 1 1
Is it because I am using the double array format? any help will be appreciated.
Thank you

 Respuesta aceptada

David Hill
David Hill el 2 de Mzo. de 2022
B=sortrows(A);%if you just sort based on columns [1 2] no sorting will happen since then are all equal

1 comentario

Hamdan Almusaibeli
Hamdan Almusaibeli el 2 de Mzo. de 2022
Editada: Hamdan Almusaibeli el 2 de Mzo. de 2022
Hi David,
Thank you so much for the prompt response. Appreciate your answer.
That makes sense.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by