Effacer les filtres
Effacer les filtres

Sort the matrix in ascending order

5 vues (au cours des 30 derniers jours)
Riya Augustine
Riya Augustine le 8 Nov 2016
Réponse apportée : Jan le 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

Réponses (2)

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

Connectez-vous pour commenter.


Jan
Jan le 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');

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by