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
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)
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