How to find the points in specific areas of the graph

1 次查看(过去 30 天)
When i plug this into matlab i am trying to get the amount of dots per area in the graph produced. (ar1...ar4). I tried to find the area above and below sections of the lines that run through the graph but I keep messing it up. What can I change to correct this issue?
n =
for k = 1:20
x = 8 * rand(1,n);
y = 8 * rand(1,n);
hold off
scatter (x,y)
hold on
u = [0:0.01:8];
for i = 1: length(u)
v1(i) = u(i);
if u(i) <= 8
v2(i) = 8-u(i);
u(i) - u(i);
end
end
plot(u,v1,u,v2)
ar1 = 0;
ar2 = 0;
ar3 = 0;
ar4 = 0;
for i = 1:length(x)
if y(i) > x(i)
ar1 = ar1 +1;
else
if y(i)< 8-x(i)
ar2 = ar2 +1;
else
ar3= ar3+1;
end
end
end
end

回答(1 个)

KSSV
KSSV 2018-12-11
YOu have the lines/ boundaries of your required area in hand. Use inpolygon to get the points/ dots that lie inside the give area. Read about inpolygon.

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by