Sorting an array in matlab
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello all
A= [12,8,15,6,26]
I have this array and i want to sort it descending
Can you write the code for this qeustion by using for and if
THANK YOU
2 commentaires
Happy Bear
le 6 Mai 2020
A similar question has already been answered here: https://www.mathworks.com/matlabcentral/answers/86608-how-to-sort-an-array-in-descending-order
Arif Istiak Abeg
le 6 Mai 2020
Réponses (2)
Arif Istiak Abeg
le 6 Mai 2020
Use the following code :
A=[12,8,15,6,26];
Ans = sort(A)
3 commentaires
Guillaume
le 6 Mai 2020
See how do I get help on homework question. Don't expect us to do your homework for you if you show no effort.
Arif Istiak Abeg
le 6 Mai 2020
Hope it will work :
A= [12,8,15,6,26];
z=numel(A);
for c=1:z
for k=c+1:z
if A(c)<A(k)
x=A(c );
A( c) =A(k);
A(k)=x;
end
end
end
3 commentaires
Guillaume
le 6 Mai 2020
For a vector, max(size(A)) and numel(A) are identical. For arrays of any size, max(size(A)) is length(A).
I would recommend that you let the OP figure out the solution to their homework themselves.
Voir également
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!