using inpolygon as a matrix operation
古いコメントを表示
Dear All,
I'm trying to do the following. I have 2 very large vecotrs and two matrices. The two vecotrs are X and Y coordinates of random points. In the matrices are the x and y data points for circles aroud certain random points (from the first two vectors). To clarify a bit more: each row of a matrix is the X or Y coordinates for a circle, with i number of circles below eachother. So I'm trying to see which random points are in each of the circles.
How i do that now is with the following code:
for i=1:length(matrix(:,1))
% xcoord and ycoord are the coordinate vectors of random points, x and y are the
% coordinates of the circles
in = inpolygon(xcoord,ycoord,x(i,:),y(i,:));
% only take the indices where inpolygon is 1 and save those as cells
nz(i,:)={find(in)};
end
But this is slow progress. Is there a way to do this using matrix operations to speed it up?
With kind regards,
Tom
採用された回答
その他の回答 (1 件)
darova
2019 年 8 月 26 日
Use colon (:) operator
in = inpolygon(xcoord,ycoord,x(:),y(:));
4 件のコメント
Tom Wagemans
2019 年 8 月 27 日
darova
2019 年 8 月 27 日
SOrry, didn't unerstand the question. Matt's idea should work. Find centers, radii and use pdist2()
Sourav Mukherjee
2019 年 9 月 28 日
編集済み: Sourav Mukherjee
2019 年 9 月 28 日
I am facing the same problem. Did you come up with solution? In my case, I am looking for the points within a square and not circle.
darova
2019 年 9 月 28 日
Just do something like
ind1 = x0-a/2 < x & x < x0+a/2;
ind2 = y0-b/2 < y & y < y0+b/2;
ind = ind1 & ind2;
a,b - sides of your square
x0,y0 specific point (blue points)
x,y - your data (red points)

カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!