Effacer les filtres
Effacer les filtres

Sort vector using loops

2 vues (au cours des 30 derniers jours)
Amjad Green
Amjad Green le 8 Avr 2018
Déplacé(e) : Voss le 22 Août 2022
Im asked to write a code using loops(if,for while..)that will sort an input vector
  3 commentaires
Walter Roberson
Walter Roberson le 8 Avr 2018

Connectez-vous pour commenter.

Réponses (1)

Swaroopa
Swaroopa le 22 Août 2022
Déplacé(e) : Voss le 22 Août 2022
You can sort a vector using for loops in the following way in MATLAB.
function res=vectorsort(ar, n)
for i=1:n
for j=1:n-i
if ar(j) > ar(j+1)
t=ar(j);
ar(j)=ar(j+1);
ar(j+1)=ar(j);
end
end
end
res=ar;
end
Refer to the below documentation for more information:
Hope it helps.

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