-2

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

4

2 回答 2

2

尝试这个:

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

如果您将严格不等式更改为>=并且<=您还将接受边界框上的点。

于 2013-10-16T22:42:51.657 回答
1

您应该ismember()更仔细地阅读 's 文档:

作为集合数组成员的数组元素

因此,此检查与集合操作有关。

相反,您应该使用它inpolygon()来检查点是否在多边形内。

于 2013-10-16T22:33:04.930 回答