MATLAB: Arrange matrix in a ascending order

MATLABmatrix

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

Best Answer

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);