フィルターのクリア

Is there a way to use inpolygon more than once ?

2 ビュー (過去 30 日間)
Gampa Surya Abhyas
Gampa Surya Abhyas 2022 年 3 月 11 日
回答済み: Prahlad Gowtham Katte 2022 年 3 月 16 日
I am trying to use inpolygon more than once in my code, but each time when i run the program is identifying points in only one polygon.Is there a way to use inpolygon more than once ?
  2 件のコメント
KSSV
KSSV 2022 年 3 月 11 日
You can use it n number of times if your polygon is different every time.
Jan
Jan 2022 年 3 月 11 日
Yes, of course. Most likely your code conatins a bug, e.g. if you run a loop over i and use j as index of the data. If you post the relevant part of the code, we can try to find the problem.

サインインしてコメントする。

回答 (1 件)

Prahlad Gowtham Katte
Prahlad Gowtham Katte 2022 年 3 月 16 日
Hello
We can use the inpolygon function more than once in a script file. The following code shows inpolygon being used more than once for 2 different polygons.
%Co-ordinates for 1st
polygon
xv = [0.5;0.2;1.0;0;0.8;0.5];
yv = [1.0;0.1;0.7;0.7;0.1;1];
%Points to be checked with 1st polygon
xq = [0.1;0.5;0.9;0.2;0.4;0.5;0.5;0.9;0.6;0.8;0.7;0.2];
yq = [0.4;0.6;0.9;0.7;0.3;0.8;0.2;0.4;0.4;0.6;0.2;0.6];
%Points to be checked with 2nd polygon
xq2 = xq+1;
yq2 = yq+0.5;
%Co-ordinates for 2nd polygon
xv2=xv+1;
yv2=yv+1;
%Getting the indicators for inside and on the edge points
[on,in]=inpolygon(xq,yq,xv,yv);
[on2,in2]=inpolygon(xq,yq,xv2,yv2);
figure
plot(xv,yv) % 1st polygon
hold on
plot(xv2,yv2) % 2nd polygon
plot(xq(in&~on),yq(in&~on),'r+') % points strictly inside
plot(xq(on),yq(on),'r*') % points on edge
plot(xq(~in),yq(~in),'ro') % points outside
%2nd polygon
plot(xq2(in2&~on2),yq2(in2&~on2),'g+') % points strictly inside
plot(xq2(on2),yq2(on2),'g*') % points on edge
plot(xq2(~in2),yq2(~in2),'go') % points outside
hold off
For more information related to inpolygon please refer to the following link
Hope it helps.

カテゴリ

Help Center および File ExchangeElementary Polygons についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by