フィルターのクリア

help extracting coordinates from inpolygon command

1 回表示 (過去 30 日間)
Adrian Lee
Adrian Lee 2020 年 11 月 12 日
回答済み: Ameer Hamza 2020 年 11 月 12 日
i need some help about a function which does not use counter loop
i used the inpolygon command to determine which of the plotted points is within a box and which isnt
how do i extract the coordinates of the points within the command and output it in an array of x-coordinates and y-coordinates?
the code i am currently using is
delta = 1;
x = 1:delta:20;
y = 1:delta:20;
[x, y] = meshgrid(x,y);
boxx_cod = [5.5;7.5;7.5;5.5;5.5];
boxy_cod = [5.5;5.5;7.5;7.5;5.5];
[in,on] = inpolygon(x,y,boxx_cod,boxy_cod); %inpoly determines which points in box and which not
box = plot(boxx_cod,boxy_cod);
hold on
plot(x(in),y(in),'r+') % points inside
plot(x(~in),y(~in),'d') % points outside
hold off
with the output of
i know from seeing this that it is the 4 + inside and i know the coordinates
but how do i tell the function to output the coordinates?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 12 日
You already have the x and y coordinates used in plot() statement
x_coor = x(in);
y_coor = y(in);
You can output them in several ways. I suggest using fprintf
fprintf('x\ty\n')
fprintf('%d\t%d:\n', [x(in).'; y(in).'])

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by