MATLAB: Difference between two Vectors

differencevectors

I have two arrays
A = [-1 1 -2 1 -1 1 -1 -2 -1 1];
B = [-1 1 1 -1 1 -1 -1 1];
and i am wanting to find all of the values in A that do not appear in B.
So the answer would appear that
values = [-2 -2 ] % values that are in A but not B
index = [3 8] % location of 'values' in A
thanks

Best Answer

A = [-1 1 -2 1 -1 1 -1 -2 -1 1];
B = [-1 1 1 -1 1 -1 -1 1];
a=setdiff(A,B)
index=find(ismember(A,a))
values=A(index)