Clear Filters
Clear Filters

Patch Between two curves that are not functions. Crosses over

6 views (last 30 days)
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

Accepted Answer

Star Strider
Star Strider on 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.
.

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!