Effacer les filtres
Effacer les filtres

how to sort the elements of an array within a given range?

4 vues (au cours des 30 derniers jours)
bsd
bsd le 22 Fév 2012
Hai,
I used the sort() function to sort the elements of a row matrix in ascending order. Example: a=[2 5 1 3 4]; sort(a); the result was a=[1 2 3 4 5]. But I do not want to sort all the elements, I need to sort the elements only from the 2nd element till the 4th element in the above matrix. Is it possible to do this using sort(). I read doc sort, but could not find a solution to my problem. Looking for your reply.
BSD

Réponse acceptée

Grzegorz Knor
Grzegorz Knor le 22 Fév 2012
a=[2 5 1 3 4];
a(2:4) = sort(a(2:4))

Plus de réponses (0)

Catégories

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by