MATLAB: Logical vector based on matrix rows

MATLABmatrixmatrix manipulation

Let's say I have the matrix
A =
-2 1 2
1 2 3
3 1 2
4 3 4
1 1 2
and I want a logical vector in which the nth element is 1 if A(n,2:end) == [1 2] (for instance) and 0 otherwise. So in this case the result would be [1 0 1 0 1]. Of course this is just a random example, but what would be an easy, general solution to achieve this, for arbitrary matrix A (in this case as above) and row vector v (in this case [1 2])?

Best Answer

out=ismember(A(:,2:end),[1 2],'rows')'