I am trying to fill the area between the variable b (size 7301x1) and the minimum value of zaxis (size of zaxis is 1x1376, but I only want to use the minimum value of it) for xaxis (size 7301x1). I attempted the following code:
xfill = [xaxis, fliplr(xaxis)];
yfill = [min(zaxis) * ones(size(b)), b];
fill(xfill, yfill, 'r');
The code ran successfully, but it only filled the area for b, creating a triangle shape at the location of b and a separate horizontal line at the minimum zaxis. I would like to fill the area between the horizontal line and the plot of b. How can I achieve this?
I also tried using the patch function, but I got the same result. I’m pretty sure I missed something, but I have no idea what.
I tried
xfill = [xaxis, fliplr(xaxis)];
yfill = [min(zaxis) * ones(size(b)), b];
patch(xfill, yfill, 'r');
I want to fill the area between min(zaxis) and b.
I think you just need to swap the order of concatenation for yfill
, since you want b
to align with xaxis
in the original order and you can align fliplr(xaxis)
with the min zaxis
values.
xfill = [xaxis, fliplr(xaxis)];
yfill = [b, min(zaxis)*ones(size(b))];
patch(xfill,yfill,'r');
For some dummy example:
xaxis = linspace(0,10,7301);
zaxis = rand( 1, 1376 ) - 1;
b = sin( xaxis ) + xaxis;
xfill = [xaxis, fliplr(xaxis)];
yfill = [min(zaxis)*ones(size(b)), b];
patch(xfill,yfill,'r');