How do I sort an array by only one column?
조회 수: 102 (최근 30일)
이전 댓글 표시
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.
This is a copy of the data unsorted.
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.
댓글 수: 0
채택된 답변
dpb
2019년 3월 17일
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!