sorting vector by value and position

3 vues (au cours des 30 derniers jours)
Tomas
Tomas le 5 Nov 2022
Commenté : Tomas le 5 Nov 2022
Hello, i need to sort this vector by value and also keep the position [109 97 116 108 97 98] to [5 1 6 4 2 3].
Any ideas how to do it?

Réponse acceptée

Torsten
Torsten le 5 Nov 2022
A = [109 97 116 108 97 98];
[~,p] = sort(A,'ascend');
r = 1:length(A);
r(p) = r
r = 1×6
5 1 6 4 2 3
  1 commentaire
Tomas
Tomas le 5 Nov 2022
Thank you so much.

Connectez-vous pour commenter.

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