Clear Filters
Clear Filters

Sort the matrix in ascending order

5 views (last 30 days)
Riya Augustine
Riya Augustine on 8 Nov 2016
Answered: Jan on 8 Nov 2016
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

Answers (2)

Walter Roberson
Walter Roberson on 8 Nov 2016
reshape(sort(im1_std1(:)), size(im1_std1)
  1 Comment
Guillaume
Guillaume on 8 Nov 2016
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.

Sign in to comment.


Jan
Jan on 8 Nov 2016
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');

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!