How to count points outside the bound in scatter plot?

조회 수: 2 (최근 30일)
Mahesh
Mahesh 2014년 9월 15일
댓글: Mahesh 2014년 9월 15일
Dear all, I would like to count the points outside the bands as shown
in blue line which is 10% band in both side. The code is like this
ndata = length(data);
X = linspace(0, 1, ndata);%ndata is number of point
x = data/max(data); % data is normalized to 1
y = dy/max(dy);
xL = linspace(0.1,1, ndata); xL = xL(:); % lower line of band
yL = linspace(0,0.9, ndata); yL = yL(:);
xU = linspace(0,0.9, ndata); xU = xU(:);
yU = linspace(0.1,1, ndata); yU = yU(:);
hold on
plot(x, y, '.k')
plot(X, X, '-k'); X = X(:); % 45 degree angled line
plot(xL, yL, '-B'); % lower line of band
plot(xU, yU, '-B'); % upperline of band
pnts = [x y];
d1 = sqrt((x-X).^2+(y-X).^2); % calculation of distance between points
idout = find(d1>0.10); % here is the 10% band width and finding distance greater than 0.1
xOut = x(idout);
yOut = y(idout);
plot(xOut, yOut, '.r'); Want to display points outside the band in red
hold off
However I got something like this
</matlabcentral/answers/uploaded_files/18174/After.png> this is not the correct one. I think there is some algorithm problem or problem in handling code. Could any one help me in this regard. In fact, I just want the number of points oun side the band rather than plot. Plot is just the confirming.
Thanks in advance.

채택된 답변

Michael Haderlein
Michael Haderlein 2014년 9월 15일
I'm not exactly sure what's going on here (the link to your file does not work). However, if you want all data outside the lower/upper lines to be marked, you don't need some square root.
upperlim=y>x+0.1;
lowerlim=y<x-0.1;
plot(x(upperlim),y(upperlim),'ro')
plot(x(lowerlim),y(lowerlim),'co')
fprintf(1,'Data below limits: %d; data above limits: %d',sum(lowerlim),sum(upperlim))
  댓글 수: 3
Mahesh
Mahesh 2014년 9월 15일
As you suggested I got like this
which is also not correct the code is like this
idU = y > X+0.1;
idL = y > X-0.1;
plot(x(idU), y(idU), '.b')
plot(x(idL), y(idL), '.r')
I am not sure why.
Mahesh
Mahesh 2014년 9월 15일
even with such code
idU = x > X+0.1 & y > X+0.1;
idL = x < X-0.1 & y > X-0.1;
does it make sense please?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by