Filter löschen
Filter löschen

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

9 Ansichten (letzte 30 Tage)
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 ?

Akzeptierte Antwort

Matt J
Matt J am 16 Feb. 2023
Bearbeitet: Matt J am 16 Feb. 2023
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 Kommentare
Matt J
Matt J am 17 Feb. 2023
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by