# Delete parts of plotted figures?

7 views (last 30 days)
ErikJon Pérez Mardaras on 23 Oct 2020
Commented: Star Strider on 28 Oct 2020 with this code:
axis equal
hold on
caca=2*pi();
ang=linspace(0,caca);
xp=5*cos(ang);
yp=5*sin(ang);
circ=[xp;yp];
plot(xp,yp,'r');
L1=[-8 8; 3 3];
plot(L1(1,:),L1(2,:),'b')
And I want to delete the part of the line within the circle and the part of the circle under the line so the image results like this: Is there any way of achieving that? How can I do it?

Star Strider on 23 Oct 2020
Try this:
axis equal
hold on
caca=2*pi();
ang=linspace(0,caca);
xp=5*cos(ang);
yp=5*sin(ang);
circ=[xp;yp];
L1x = linspace(-8, 8);
L1y = 3*ones(size(L1x));
L1=[L1x; L1y]; % Re-define Line
incirc = inpolygon(L1x,L1y,circ(1,:),circ(2,:));
L1(1,incirc) = NaN;
L1(2,incirc) = NaN;
plot(xp(yp>=3),yp(yp>=3),'r');
plot(L1(1,:),L1(2,:),'b')
.

Show 1 older comment
Star Strider on 25 Oct 2020
Increase the resolution of ‘ang’ and ‘L1x’ and the gaps essentially disappear:
ang=linspace(0,caca, 5000);
. . .
L1x = linspace(-8, 8, 5000);
producing: There will always be small gaps because there are not an infinite number of points in ‘ang’ and ‘L1x’.
ErikJon Pérez Mardaras on 28 Oct 2020
thanks!
Star Strider on 28 Oct 2020
As always, my pleasure!

Fangjun Jiang on 23 Oct 2020
use patch() or fill()? This one does part of it.
patch(xp,yp,'white')

#### 1 Comment

ErikJon Pérez Mardaras on 25 Oct 2020
I have tried that and appears and strange figure with black borders

R2019b

### Community Treasure Hunt

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

Start Hunting!