MATLAB: Finding intersecting rows in column vectors of varying length

findintersectMATLAB

Hello, I have 2 column vectors of different lengths and I would like to find instances in each vector with the same value. For example if vector 1 is:
v1x=[1:0.1:10];
v1y=[20:2:200];
And vector 2 is:
v2x=[1;6.5;9;10;10;1;2.3];
v2y=[20;62;26;30;200;96;200];
I would like to create a 3rd column vector with each “intersecting” instance such that:
v1x==v2x and v1y==v2y.
This should return for the example above, row =1 ,where
v1x=1=v2x and v1y=20=v2y
and
row =5, where v1x=10=v2x and v1y=200=v2y.
Thanks
Gareth

Best Answer

>> [~,~,ix]=intersect([v1x(:) v1y(:)],[v2x v2y],'rows')
ix =
1
5
>>