How can I fill multiple polygons from the same vector?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone! I have a problem that seems to be trivial, but that I cannot solve. I have two vectors x=[...] and y=[...]. These two vectors contain the coordinates of three polygons, divided by NaN. I would like to fill these three areas without splitting the vectors (two red squares and one red triangle). Here is the code
x = [0 1 1 0 NaN 2 3 3 2 2 NaN -1 1 1 -1 -1];
y = [0 1 2 0 NaN 3 3 4 4 3 NaN 4 4 5 5 4];
figure
plot(x,y,'k'); hold on
fill(x,y,'r','LineStyle','none')
I also tried to remove NaN, without success.
x1 = [0 1 1 0 2 3 3 2 2 -1 1 1 -1 -1];
y1 = [0 1 2 0 3 3 4 4 3 4 4 5 5 4];
figure
fill(x1,y1,'r','LineStyle','none')
Any suggestions? Thank you!
0 commentaires
Réponse acceptée
jonas
le 10 Août 2018
Modifié(e) : jonas
le 21 Août 2018
Use patch. Each patch is defined by the coordinates of the columns of the input matrix. As such, all patches must have the same number of coordinates. You can pad the shorter patches by repeating the last coordinate.
x = [0 1 1 0 0, 2 3 3 2 2,-1 1 1 -1 -1];
y = [0 1 2 0 0, 3 3 4 4 3, 4 4 5 5 4];
x=reshape(x,5,3)
y=reshape(y,5,3)
h=patch(x,y,[1;0;2]);
6 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Line Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

