You should read ismember()
's documentation more carefully:
Array elements that are members of set array
So, this check is related to set operations.
Instead, you should use inpolygon()
to check whether points are inside a polygon.
質問
I have an array of points or locations that are scattered throughout a big matrix, and I have a small bounding box inside the matrix. I need a way to check if the points in the array are within the bounding box. Thanks for your suggestions.
BoundingBox = [BB1,BB2,BB3,BB4];
Array = [x1,y1;x2,y2;x3,y3;x4,y4;x5,y5;x6,y6];
I have tried
ismember([BB1,BB2,BB3,BB4],Array);
and
ismember(rectangle('Position',[BB1,BB2,BB3,BB4]),Array);
but nothing is working
解決 2
You should read ismember()
's documentation more carefully:
Array elements that are members of set array
So, this check is related to set operations.
Instead, you should use inpolygon()
to check whether points are inside a polygon.
他のヒント
Try this:
% Array an Nx2 matrix containing the X,Y coordinates of the points with
% respect to the big matrix
%
% BoundingBox a vector of length 4 representing the bounding box as follows:
% [minimumX, minimumY, sizeX, sizeY]
isInBox = @(M,B) (M(:,1)>B(1)).*(M(:,1)<B(1)+B(3)).*(M(:,2)>B(2)).*(M(:,2)<B(2)+B(4));
isInBox(Array,BoundingBox);
If you change the strict inequalities to >=
and <=
you will also accept points on the bounding box.