필터 지우기
필터 지우기

Sort the matrix in ascending order

조회 수: 5 (최근 30일)
Riya Augustine
Riya Augustine 2016년 11월 8일
답변: Jan 2016년 11월 8일
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

답변 (2개)

Walter Roberson
Walter Roberson 2016년 11월 8일
reshape(sort(im1_std1(:)), size(im1_std1)
  댓글 수: 1
Guillaume
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
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');

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by