Effacer les filtres
Effacer les filtres

Patch Between two curves that are not functions. Crosses over

6 vues (au cours des 30 derniers jours)
Adam Watts
Adam Watts le 14 Sep 2023
Commenté : Star Strider le 18 Sep 2023
I am having trouble fillling the area between {x1, y1} and {x2, y2} without it crossing over. Ideally it should be a filled Elbow shape without crossing over each other. I tried patch and fill functions and I get similair behavior.
x1 = [1 1 1 2.5 5];
y1 = [5 2.5 1 1 1];
x2 = [2 2 5];
y2 = [5 2 2];
hold on
plot(x1, y1, LineStyle=":");
plot(x2, y2, LineStyle=":");
xlim([0, 6])
ylim([0, 6])
fill([x1, x2], [y1, y2], 'k', 'FaceAlpha',0.2)
hold off

Réponse acceptée

Star Strider
Star Strider le 14 Sep 2023
Perhaps this —
x1 = [1 1 1 2.5 5];
y1 = [5 2.5 1 1 1];
x2 = [2 2 5];
y2 = [5 2 2];
figure
hold on
plot(x1, y1, LineStyle=":");
plot(x2, y2, LineStyle=":");
xlim([0, 6])
ylim([0, 6])
patch([x1 flip(x2)], [y1 flip(y2)], [1 1 1]*0.5, 'EdgeColor','none')
% fill([x1, x2], [y1, y2], 'k', 'FaceAlpha',0.2)
hold off
The patch function fills a closed region, defined by its arguments. If you want to fill between the lines, that is relatively straightforward.
.
  2 commentaires
Adam Watts
Adam Watts le 18 Sep 2023
Thanks! That did the trick!
Star Strider
Star Strider le 18 Sep 2023
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Lighting, Transparency, and Shading dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by