Sort the matrix in ascending order
조회 수: 5 (최근 30일)
이전 댓글 표시
I want to sort the matrix in ascending order
Original matrix
im1_std1 =
70.7293 55.2429
66.5829 65.4434
57.9615 69.1739
66.0494 70.9296
but the result is
>> sort(im1_std1,'ascend')
ans =
57.9615 55.2429
66.0494 65.4434
66.5829 69.1739
70.7293 70.9296
I want a code to get result like this
ans=
55.2429 57.9615
65.4434 66.0494
66.5829 69.1739
70.7293 70.9296
Thanks in advance
댓글 수: 0
답변 (2개)
Walter Roberson
2016년 11월 8일
reshape(sort(im1_std1(:)), size(im1_std1)
댓글 수: 1
Guillaume
2016년 11월 8일
Actually,
reshape(sort(im1_std1(:)), fliplr(size(im1_std1))).'
Note to Riya Augustine, why are you storing it as a matrix when a) neither columns nor rows have any meaning since numbers can move between any of them b) you're using the opposite convention to matlab (where order goes down rows first, then column). Why not store it all in a single vector and avoid all this dimension swapping.
Jan
2016년 11월 8일
There is an infinite number of procedures to convert your input to the shown output. If you explain the meaning of the wnated operation, suggestion an answer will not demand bold guessing.
Perhaps you want:
s1 = sort(im1_std1, 1, 'ascend');
result = sort(s1, 2, 'ascend');
댓글 수: 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!