Find common elements.
Syntax
[XI,YI] = wcommon(X,Y)
Description
wcommon is a general utility.
For two vectors X and Y with integer components, [XI,YI] = wcommon(X,Y)
returns two vectors with 0 and 1 components such that:
XI(k) = 1 if X(k) belongs to Y; otherwise XI(k) = 0 and
YI(j) = 1 if Y(j) belongs to X; otherwise YI(j) = 0.
Examples
% Define two vectors.
x = [ 10 20 30 40 50 ];
y = [ 60 50 70 30 20 12 31 ];
% Find common elements.
[xi,yi] = wcommon(x,y)
xi =
0 1 1 0 1
yi =
0 1 0 1 1 0 0
% List common elements.
comelem = x(find(xi))
comelem =
20 30 50
[ Previous | Help Desk | Next ]