# Thread: Sorting the all array in MATLAB

1. ## Sorting the all array in MATLAB

Hey all, simple question if I may.

I've got a simple 5X5 matrix that I want to sort all of the numbers of the array in an ascending order ( The first column will be the smallest numbers, the second column will contain the next numbers and so on ...)
I've tried the 'sort' and 'sortrows' functions with no luck. It's only working for individual columns.

Any ideas ?

Thanks.

2. Originally Posted by Geomorphologist
Hey all, simple question if I may.

I've got a simple 5X5 matrix that I want to sort all of the numbers of the array in an ascending order ( The first column will be the smallest numbers, the second column will contain the next numbers and so on ...)
I've tried the 'sort' and 'sortrows' functions with no luck. It's only working for individual columns.

Any ideas ?

Thanks.
Code:
xx=rand(3,3)
sz=size(xx)

xx=reshape(xx,1,sz(1)*sz(2))
xx=sort(xx)
xx=reshape(xx,sz(1),sz(2))
CB

3. Thanks, working like a charm