MATLAB: How to sort a matrix by a predefined order how to set the order of a matrix I have a matrix, A=[1 2; 3 4; 5 6; 7 8], how to reset the order by B=[1; 4; 3; 2] to get A = [1 2; 7 8; 5 6; 3 4]? Thanks, Best Answer A=[1 2; 7 8; 5 6; 3 4];B=[1; 4; 3; 2];A = A(B,:); Related SolutionsMATLAB: QUESTION ON MATRIX RESHAPING a = reshape(1:9,3,[])';out = kron(a,ones(3));orout = repelem(A,3,3) MATLAB: Find missing element between two matrix >> A = [1,2;3,6;3,5;1,4;4,6;2,7;1,6;6,5;2,3;6,7;3,4];>> B = [1,2;1,6;2,3;3,4;4,6];>> R = setdiff(A,B,'rows')R = 1 4 2 7 3 5 3 6 6 5 6 7To get the same order, use the 'stable' option or this:>> [~,X] = setdiff(A,B,'rows');>> X = sort(X);>> R = A(X,:)R = 3 6 3 5 1 4 2 7 6 5 6 7 Related QuestionMatrix change affect other matrixFill in a Matrix with predefined numbers
Best Answer