How to fill a 2D plot?

5 vues (au cours des 30 derniers jours)
Kevin
Kevin le 4 Nov 2021
Modifié(e) : Dave B le 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?

Réponse acceptée

Dave B
Dave B le 4 Nov 2021
Modifié(e) : Dave B le 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])

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by