intersect
Returns the elements in both a and b.
Syntax
intersect(a,b)
intersect(a,b,'rows')
[x,y,z] = intersect(a,b)
Inputs
- a,b
- The sets to search for common elements in.
- 'rows'
- Specifies to search for common rows as opposed to common elements.
Outputs
- R
- Common elements in ascending order.
- x,y,z
- x is the list of elements common to both sets (a and b).
Examples
Simple intersect example:
intersect([1,5,2;6,2,6],[9;0;1;2])
R = [ 1 ; 2 ]
Simple intersect example with multiple returns:
[a,b,c]=intersect([1,5,2;6,2,6],[9;0;1;2])
a = [ 1 ; 2 ]
b = [ 1 ; 5 ]
c = [ 3 ; 4 ]
Simple intersect example with rows option:
intersect([1,5,2;6,2,6],[9,0,1;6,2,6],'rows')
ans = [Matrix] 1 x 3
6 2 6