Arrange matrix in a ascending order

2 views (last 30 days)
Hi Guys,
If I have a matrix say of the following form
X = 42.5123 42.3975 42.2375 42.1167 42.1354 41.8895
67.7294 67.6697 67.6345 67.5530 67.5784 67.4758
I want to arrange it in such a way that the if the last element in the first row is the smallest element (like the eg above), I want to reverse the order completely.
X= 41.8895 42.1354 42.1167 42.2375 42.3975 42.5123
67.4758 67.5784 67.5530 67.6345 67.6697 67.7294
You can see that the order is just reversed. Can anyone tell me how I can accomplish this in MATLAB.
Thanks, Nancy

Accepted Answer

Walter Roberson
Walter Roberson on 9 Nov 2011
If you know that you are reversing from side to side, then just
newX = fliplr(X);
Otherwise,
[sortX, xidx] = sort(X(1,:));
newX = X(:,xidx);
  1 Comment
chengxuan yu
chengxuan yu on 9 Nov 2011
Just use the function 'fliplr' that above could be the best choose!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!