Patch Between two curves that are not functions. Crosses over

6 ビュー (過去 30 日間)
Adam Watts
Adam Watts 2023 年 9 月 14 日
コメント済み: Star Strider 2023 年 9 月 18 日
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

採用された回答

Star Strider
Star Strider 2023 年 9 月 14 日
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 件のコメント
Adam Watts
Adam Watts 2023 年 9 月 18 日
Thanks! That did the trick!
Star Strider
Star Strider 2023 年 9 月 18 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by