MATLAB: How to arrange ascending order only one column of a matrix arrayascendingmatrix Let's say, I have a=[25 10 85 35 71; 1 2 3 4 5] and output shout come b=[10 25 35 71 85; 2 1 4 5 3] Best Answer b=sortrows(a.').' Related SolutionsMATLAB: Matrix problem for same values of column N = size(A,1);X = ones(N,1); % group numbersZ = true(N,1); % logical indexV = 1; % group numberfor k = 2:N % for each row... Y = A(k,2)==A(1:k-1,3); % check if any matching rows. if any(Y) X(k) = X(Y); % copy group number (assumed scalar). W = X(k)==X(1:k-1); % logical index of that group. if all(A(k,1)>A(W,1)) Z(W) = false; % current val > prev vals. else Z(k) = false; % prev val > current val. end else % no matching rows: V = V+1; % increment group number. X(k) = V; endendB = A(Z,:) % output matrixGiving:B = 22.98 4 12 25.53 26 29 21.43 2 32 29.94 11 33 29.57 15 35 13.69 37 38 26.97 28 39 4.24 18 42 29.93 16 45 25.83 30 46 26.09 40 47 28.61 41 49 29.41 48 50 MATLAB: Sort a line of the matrix and change the other lines according the line sorted Use sortrows.a = a'; % transpose your matrixasorted = sortrows(a,1); % sort by first column (row)asorted = asorted'; % de-transpose your matrixYou can combine all that code into one line:asorted = sortrows(a')'; Related QuestionSort a matrix with indexingPlease help me sort this outSearch matrix for array of values and place results into anotherHow to sort or rearrange a column with respect to the other column?!Sort Matrix by rowsMatrix Manipulation Image Processing
Best Answer