How to fill a 2D plot?

7 visualizzazioni (ultimi 30 giorni)
Kevin
Kevin il 4 Nov 2021
Modificato: Dave B il 4 Nov 2021
close all
clear
clc
hold on
grid on
P_outside = ([0.1+0.6i,0.3+0.6i,0.4+0.8i,0.3+i,0+i,0+0.5i,0,0.1+0i,0.1+0.6i]);
P_inside = ([0.1+0.7i,0.21+0.7i,0.21+0.9i,0.1+0.9i,0.1+0.7i]);
plot(P_outside)
plot(P_inside)
xlim([-0.2,1])
ylim([-0.1,1])
I would like to fill the 'P' with a color, how do I do that?

Risposta accettata

Dave B
Dave B il 4 Nov 2021
Modificato: Dave B il 4 Nov 2021
You can use the fill function to fill a region. You can retrieve the x and y values using real and imag (I don't think fill does the same trick of splitting complex numbers like plot does)
P_outside = ([0.1+0.6i,0.3+0.6i,0.4+0.8i,0.3+i,0+i,0+0.5i,0,0.1+0i,0.1+0.6i]);
P_inside = ([0.1+0.7i,0.21+0.7i,0.21+0.9i,0.1+0.9i,0.1+0.7i]);
x=[real(P_outside) real(P_inside)];
y=[imag(P_outside) imag(P_inside)];
fill(x,y,'r','EdgeColor','none')
xlim([-0.2,1])
ylim([-0.1,1])

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by