Matching X and Y co-ordinated from the reference xy

조회 수: 2 (최근 30일)
SatyaPrakash Gupta
SatyaPrakash Gupta 2019년 12월 9일
편집: Rik 2019년 12월 9일
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.
  댓글 수: 2
darova
darova 2019년 12월 9일
What about 1 and 4?
SatyaPrakash Gupta
SatyaPrakash Gupta 2019년 12월 9일
Yes i would like to return all the matched value in an array.
Please note : the dimension of X will have different size

댓글을 달려면 로그인하십시오.

채택된 답변

Rik
Rik 2019년 12월 9일
편집: Rik 2019년 12월 9일
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)
  댓글 수: 3
SatyaPrakash Gupta
SatyaPrakash Gupta 2019년 12월 9일
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
Rik 2019년 12월 9일
편집: Rik 2019년 12월 9일
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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by