How to find the number of point inside the graph?

조회 수: 4 (최근 30일)
Ellina
Ellina 2015년 5월 20일
댓글: Andrei Bobrov 2015년 5월 21일
Hello,
  • I have made a graph and inserted many random points.
  • I marked the point manually in orange color for points outside the graph and green color for points inside the graph
  • I wonder how can we calculate the number of points in green color automatically using only MATLAB code?
Thank you in advance

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2015년 5월 20일
편집: Andrei Bobrov 2015년 5월 20일
x = [0,7, 18, 37,47,54,57.5,59,61.5,69,87,95,99,103,110]'/110; % Let this
y = [0, 15,43,53,42,20,7,0, 37, 61,56, 40.5, 24, 6, 0]'/61; % is arrays - your data
f = griddedInterpolant(x,y,'pchip'); % old MATLAB: pp = interp1(x,y,'pchip','pp');
% f = @(x)ppval(pp,x);
xx = rand(100,1);
yy = rand(100,1)*1.3; % points for check
t = f(xx) - yy > 0;
plot(0:.001:1,f(0:.001:1));grid on
hold on
plot(xx(t),yy(t),'g*');
plot(xx(~t),yy(~t),'r*');
  댓글 수: 2
Ellina
Ellina 2015년 5월 21일
Thank you so much.
The logical code,t helps me a lot.
I already plotted the graph but I don't know how to count automatically the number of green point.
Still trying my best to code it.
Andrei Bobrov
Andrei Bobrov 2015년 5월 21일
number of green point:
NG = sum(t);
or
NG = nnz(t);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by