-3

I have this problem that I need to sort a matrix in MATLAB.

Input:(2x5 matrix)

1    2
3    4
5    6
7    8
9    10

And I'd like the output to be.(2x5)

9   10
7   8
5   6
3   4
1   2

I would like to invert first matrix, help is needed.

2 Answers2

3

That's just some basic matrix indexing, using the colon operator:

M(end:-1:1,:)
Daniel
  • 36,610
  • 3
  • 36
  • 69
2

Flip the array upside down by using flipud.

A = [1, 2; 3, 4; 5, 6; 7, 8; 9, 10];
B = flipud(A);
mikkola
  • 3,376
  • 1
  • 19
  • 41
  • Thank you so much for help. – Asen Martin Nov 28 '15 at 17:44
  • 2
    @Asen Martin is this a solution? You said you want to "sort a matrix," which is in general different from `flipud`, although they are the same for your example. It's not clear whether you want to sort each column individually, or as groups using `sortrows`. – Jeff Irwin Nov 28 '15 at 18:14
  • 1
    @JeffIrwin that is a good point. The OP was using "invert" and "sort" both, along with a sample output. This answer is just my best interpretation. – mikkola Nov 28 '15 at 20:02