Doug's MATLAB Video Tutorials

September 11th, 2007

MATLAB Basics video: Sorting matrices

This video covers how to sort a matrix, either sorting each column independently or sorting such that the original rows stay together. Most new users are able to find the SORT command without much problem, but the very useful SORTROWS is often missed.
Find the files here. Other videos have been gathered here: http://blogs.mathworks.com/pick/category/video/ Other MATLAB Basics posts have been gathered here: http://blogs.mathworks.com/pick/category/matlab-basics/

5 Responses to “MATLAB Basics video: Sorting matrices”

  1. slaesche replied on :

    Good tip! Just what I was looking for. Thanks.

  2. mayank replied on :

    Hi,I want to sort the coordiantes.How to do this?
    Eg- 1 0
    3 2
    21 0
    4 4
    2 3
    5 4
    so that the sorted coordinates come out to be:
    1 0
    21 0
    3 2
    2 3
    4 4
    5 4

  3. Doug replied on :

    Mayank,

    Please watch the video again. You will see Sortrows at the end. This is the function you are looking for.

    Doug

  4. Sanchay Subhedar replied on :

    I am getting this error on using simple sort function on the same magic square as your.

    ??? Index exceeds matrix dimensions.

    How can I “sort” this problem ;-)

  5. Doug replied on :

    Sanchay,

    You need to show all the relevant code to get help.

    Doug

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.