MATLAB: What is the result

matrix

X a matrix 2 × n containing the coordinates of n points of the plan. How to obtain a matrix where the points are ordered by ascending order of the x-axis?

Best Answer

n = 100 ;
X = rand(2,n) ; % some random data
[val,idx] = sort(X(1,:),'ascend') ; % sort x values (first row) in ascending order
X = X(:,idx) ;