I'm trying to fill the areas between a polyline and a horizontal line (that cut this polyline in several points) using Octave/Matlab, but I want to keep only the areas below the horizontal line.
This is what I've come up so far:
x = 0:0.5:6;
y = [3 2.5 1 1 1 2.5 3 2.5 1 1 1 2.5 3];
yline(1:13) = 2;
figure(1)
plot(x,y,'k')
fill([x fliplr(x)],[y yline],'g')
axis equal
xlim([-1 7]);
I searched for days to find a solution but I only went close to the answer here, here and here (unfortunately this last one is only for r-code).
You can use the following trick:
patch
to cover the part you don't want filled. No edge color here either.Code:
x = 0:0.5:6;
y = [3 2.5 1 1 1 2.5 3 2.5 1 1 1 2.5 3];
yline(1:13) = 2;
figure(1)
fill([x fliplr(x)],[y yline],'g', 'edgecolor', 'none')
hold on
patch([min(x) max(x) max(x) min(x)],[yline(1) yline(1) max(y) max(y)], 'w', ...
'edgecolor', 'none')
plot(x,y,'k')
plot(x,yline,'k')
axis equal
xlim([-1 7]);
Resulting figure: