how can i sort columns of a matrix in ascending order using loops without using the functions max,min,sort?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ciro saravia
le 1 Juil 2018
Réponse apportée : Jonathon Gibson
le 1 Juil 2018
I have a 15x10 matrix with numbers and i need to sort each column in ascending order
0 commentaires
Réponse acceptée
Jonathon Gibson
le 1 Juil 2018
Here's a really simple, inefficient way:
M = rand(15,10)
for col = 1:size(M,2)
for iters = 1:size(M,1)
for row = 1:(size(M,1)-1)
if (M(row,col) > M(row+1,col))
temp = M(row,col);
M(row,col) = M(row+1,col);
M(row+1,col) = temp;
end
end
end
end
M
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur String 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!