MATLAB: Ordering a column with respect to another column.

MATLABpermutation

Hi, I have a matrix with 2 columns and N (=50) rows. The columns have positive real numbers. I intend to order the elements of column 1 keeping column 2 fixed so that column 1 and column 2 become oppositely arranged. In other words, keeping column 2 fixed, re-order column 1 so that
corr(column 1, column 2, 'type', 'Kendall') = -1
Any ideas on how I can proceed with this?
Many Thanks!

Best Answer

This should do it:
A=rand(50,2);
[~,J]=sort(A(:,2),'descend');
A(J,1)=sort(A(:,1),'ascend');
corr(A(:,1), A(:,2) , 'type', 'Kendall')