How can i sort a matrix with loops?
Show older comments
I need to sort each row of a matrix (without sort function) in ascending order using loops and im confused about how i would go about switching values within the row to order them.
Answers (1)
Sean de Wolski
on 19 Nov 2013
x = [1 2 5 4]
For example, t switch the 5 and the 4
x([3 4]) = x([4 3]) %switch linear indices.
Categories
Find more on Shifting and Sorting Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!