MATLAB: Removing like terms in a matrix

matrixmatrix manipulationsubtraction

Let say i have to matrix A and B and wanted to produce a matrix C with the different terms of A and B.
A = [1 2 3 4 5 6 7 8 9]
B = [2 4 5 8 9]
so that
C = [1 3 6 7]

Best Answer

ismember function can do this more easily, like:
A = [1 2 3 4 5 6 7 8 9];
B = [2 4 5 8 9];
idx = ismember(A,B);
C = A(~idx);