MATLAB: How to get the value of an element if it satisfies a logical condition

inpolylogical conditionvalue of element

Hello,
if I have two column vecotors, xcoord (that has some x-coordinates) and ycoord (that has some y-coordinates), How can I get the elements in xcoord and ycoord if it satisifes inpoly(xcoord,ycoord,#,*) ?
i.e. if inpoly(xcoord,ycoord,#,*) == 1 for all elements inside xcoord and ycoord.
where # and * are the coordinates of some polygon that I want to know which coordinates in xcoord and ycoord lies inside this polygon.
Thank you.

Best Answer

inpolygon gives you logical indices. From these you canget the points. Read about inpolygon and logical indexing.
idx = inpolygon(x,y,xv,yv) ; % x, y are points and xv, yv are points which form a polygon
P = [x(idx) y(idx)]; % assuming x, y are column arrays