How do I sort an array by only one column?

19 visualizaciones (últimos 30 días)
Ewan Harris
Ewan Harris el 17 de Mzo. de 2019
Comentada: madhan ravi el 18 de Mzo. de 2019
I have an array with the first column being x-coordinate, the second column being y-coordinate and then the next few columns being different values. I've used an if function so that all the y-coordinates are the same in the array but I then want to sort by x-coordinate (so my plot(x,y) is in order rather than jumping all over the place). The problem is that when I use the sort() function, it orders all my other columns too so the data is no longer associated with the correct coordinate.
Annotation 2019-03-17 123107.jpg
This is a copy of the data unsorted.
Annotation 2019-03-17 123143.jpg
This is after I've used the sort function. It also sorts column 3 which I don't want to happen. I want the 58.6480 value (column 3) to remain in the same row as the 20 value from column 1.

Respuesta aceptada

dpb
dpb el 17 de Mzo. de 2019
doc sortrows
% ALWAYS read "See Also" when looking for related functions!!!
>> help sort
sort Sort in ascending or descending order.
B = sort(A) sorts in ascending order.
...
See also issorted, sortrows, min, max, mink, maxk.
  7 comentarios
dpb
dpb el 17 de Mzo. de 2019
'S ok...we all have our moments... :) I certainly "whiff" often enough.
madhan ravi
madhan ravi el 18 de Mzo. de 2019
:)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by