# Matching X and Y co-ordinated from the reference xy

6 views (last 30 days)
SatyaPrakash Gupta on 9 Dec 2019
Edited: Rik on 9 Dec 2019
Hi,
I have list of XY coordinates i.e XY points for the given figure.
further i have extracted the required XY coordinates and now i want to match my current XY values present in reference XY coordinates, is it possible ?
could you please do help me here.
e.g
X = [ 1,2,3,4,5,6,7.6 , 8.9, 5.7 ..]
X = [1, 4,6,9,3,7.6,5.3.5.7... ]
so i want to compare this and get the result with the matched values i.e
final X = [7.6,5.7]
is there a way to do this ?
thank you.

darova on 9 Dec 2019
SatyaPrakash Gupta on 9 Dec 2019
Yes i would like to return all the matched value in an array.
Please note : the dimension of X will have different size

Rik on 9 Dec 2019
Edited: Rik on 9 Dec 2019
Although you can solve this with the ismember function, you are actually looking for the intersect function:
X = [1,2,3,4,5,6,7.6,8.9,5.7];
Y = [1,4,6,9,3,7.6,5.3,5.7];
X_new=intersect(X,Y)

SatyaPrakash Gupta on 9 Dec 2019
thank you so much it works.
Further questions:
I am using imfreehand matlab function where i am getting only the boundries of the draw picture, i am intrested to find the x and y values inside the picture instead of taking boundries value of picture , could you please do help me out ?
thank you
SatyaPrakash Gupta on 9 Dec 2019
Hi Rik,
it will not resolve the problem because as i mentioned that i am storing the x and y values of the marked using iamfreehand() so it gives only the boundy values not the values inside the boundries, therefore i cannot use this intersect function.
could you let me know how to resolve it?
thank you
Rik on 9 Dec 2019
So you have a list of coordinates that form the boundary of an object? If you have a closed loop, you can use the inpolygon function to find all grid points inside your trace.
%generate an outline
u=20;
t=linspace(0,2*pi,6);x=u+u*cos(t);y=u+20*sin(t);
[X,Y]=ndgrid(1:(2*u));
L=inpolygon(X(:),Y(:),x,y);
X_in=X(L);
Y_in=Y(L);
figure(1),clf(1)
plot(x,y,'b')
hold on
plot(X(L),Y(L),'r*')
plot(X(~L),Y(~L),'r.')
axis([0 2*u+1 0 2*u+1]) %fit axis to displayed data
daspect([1 1 1])%set aspect ratio to 1