Arrange matrix in a ascending order

2 Ansichten (letzte 30 Tage)
Nancy
Nancy am 9 Nov. 2011
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 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 Kommentar
chengxuan yu
chengxuan yu am 9 Nov. 2011
Just use the function 'fliplr' that above could be the best choose!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by