How can i sort a matrix with loops?

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)

x = [1 2 5 4]
For example, t switch the 5 and the 4
x([3 4]) = x([4 3]) %switch linear indices.

Categories

Asked:

Tom
on 19 Nov 2013

Answered:

on 19 Nov 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!