필터 지우기
필터 지우기

How do I remove points which are far away from the boundary of domain?

조회 수: 9 (최근 30일)
Hi, I would like to know how do I remove points which are far away from the boundary of domain, for example
% Before
% Set points of domain:
x= [ 0 0.5 0.5 1 1 0 0 0.5 0.75 0.25 0.25];
y = [0 0 0.5 0.5 1 1 0.5 1 0.75 0.75 0.25];
% Set center points:
xc = linspace(0,1,5);
yc = linspace(0,1,5);
[xcen,ycen] = meshgrid(xc,yc);
% Plot
figure(1);
plot(x,y,'b.','MarkerSize',4);
hold on
corner = [0 0; 0.5 0; 0.5 0.5; 1 0.5; 1 1;0 1;0 0]; % visualize the boundary domain
plot(corner(:,1),corner(:,2),'-g','linewidth',0.5);
hold on
plot(xcen,ycen,'or');
hold off
% After
% % Remove center points which are far away from the boundary of domain.
idx = knnsearch(data_r,data_b,'k',1);
xc = xc(:,unique(idx));
yc = yc(:,unique(idx));
H = min(diff(xc));
Xcen = xc(1:end-1) + 0.5*H;
Ycen = yc(1:end-1) + 0.5*H;
[xcen,ycen] = meshgrid(Xcen,Ycen);
% Plot
figure(2);
plot(x,y,'b.','MarkerSize',7);
hold on
corner = [0 0; 0.5 0; 0.5 0.5; 1 0.5; 1 1;0 1;0 0]; % visualize the boundary domain
plot(corner(:,1),corner(:,2),'-g','linewidth',0.5);
hold on
plot(xcen,ycen,'or');
hold off
The problem : there is 4 red points which are out the boundary of domain!
Question : what can i do to remove any points which are out of the boundary nodes ?

채택된 답변

Matt J
Matt J 2023년 2월 16일
편집: Matt J 2023년 2월 16일
Question : what can i do to remove any points which are out of the boundary nodes ?
Use inpolygon to detect which points are within the boundaries. Then discard the others.
  댓글 수: 6
Matt J
Matt J 2023년 2월 17일
It's a warning, not an error, so maybe nothing is wrong. You can plot it as a check,
plot(polyshape(data_boundary))
I suspect that the points in data_boundary are not listed in the proper order.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by