MATLAB: How to fill between two curves, but only when one curve is above the other

between two curvesfillshading

Hello,
I'd like to fill the gap between two lines, but only when one line is above the other.
With the data file attached and the command:
plot(x,y1,'k',x,y2,'k:');
hold on;
xlim([x(1) x(end)]);
jbfill(x',y1',y2',[.8 .8 .8],'none',0,.5);
legend('y1','y2');
hold off;
I can plot:
Figure.png
which always fills the gap between y1 and y2. But I'd like it to be filled only when y1>y2.
Any help on this is very welcome.
Best,

Best Answer

You can do a little trick:
plot(x,y1,'k',x,y2,'k:');
hold on;
xlim([x(1) x(end)]);
y1tmp = y1;
y1tmp(y1<y2) = y2(y1<y2);
jbfill(x',y1tmp',y2',[.8 .8 .8],'none',0,.5);
legend('y1','y2');
hold off;