inpolygon help

  • Follow


I am trying to use the inpolygon command. I want it to eventually be used in a function where the user passes the dimensions of an image to it. It will also be passed several points that the user selected with ginput.

However, I am unsure of how to use inpolygon. From the way I understand it, 

IN = inpolygon(X,Y,xv,yv)

X and Y must be the same size, and X represents the x value at each point in the matrix, and Y represents the y values in the matrix. xv is a vector containing the x-values of the user defined points, and yv is a vector containing the y-values of the user defined points.

This is how I am trying to implement it:

matrix=zeros(14,8); % 14 and 8 will eventually be passed as variables to the function
x=[3,1,5,6];           % x and y will eventually be vectors passed as variables 
y=[1,6,11,7];         % to the function   

%The following creates the matrixes X and Y for inpolygon
[rows,cols]=size(matrix);
for i=1:1:cols
    xvals=i;
end
for i=1:1:rows
    yvals=i;
end
yvals=yvals';
[Xvals,Yvals]=meshgrid(xvals,yvals);

xpoint=x+1; %Because the user defined inputs have the reference at 0,0               
ypoint=y+1; %and the matrixes will be indexed from variable(1,1)

matrix=inpolygon(Xvals,Yvals,xpoint,ypoint)

However I get the following error/output

??? Error using ==> and
Inputs must have the same size.

Error in ==> inpolygon at 77
mask = (x >= min(xv)) & (x <= max(xv)) &
(y>=min(yv)) & (y<=max(yv));

Error in ==> mask at 54
matrix=inpolygon(rows,cols,xpoint,ypoint)
 

matrix =

     0

EDU>> 
0
Reply Nicholas 1/9/2011 1:09:04 AM

"Nicholas Trunfio" <Nicholas_Trunfio@student.uml.edu> wrote in message <igb1rg$rlp$1@fred.mathworks.com>...

> for i=1:1:cols
>     xvals=i;
> end
> for i=1:1:rows
>     yvals=i;
> end

Your loop erase data over an over.

Beside that the code runs. You probably make another mistake when test it.

Bruno
0
Reply Bruno 1/9/2011 10:20:21 AM


1 Replies
694 Views

(page loaded in 0.027 seconds)

Similiar Articles:













7/22/2012 8:28:44 PM


Reply: