MATLAB: How to fill space between two lines

betweenfillhow toMATLABspace

Hi, I have this code:
H_up = [0,cosd(80)*7.387/10,cosd(70)*7.985/10,cosd(60)*8.906/10,cosd(50)*1.025,cosd(40)*1.238,cosd(30)*1.155,cosd(20)*1.064,cosd(10)*1.015,1];
H_lo = [0,cosd(80)*7.243/10,cosd(70)*7.826/10,cosd(60)*8.734/10,cosd(50)*1.009,cosd(40)*1.218,cosd(30)*1.137,cosd(20)*1.062,cosd(10)*1.015,1];
M_up = [7.021/10,sind(80)*7.387/10,sind(70)*7.985/10,sind(60)*8.906/10,sind(50)*1.025,sind(40)*1.238,sind(30)*1.155,sind(20)*1.064,sind(10)*1.015,0];
M_lo = [6.897/10,sind(80)*7.243/10,sind(70)*7.826/10,sind(60)*8.734/10,sind(50)*1.009,sind(40)*1.218,sind(30)*1.137,sind(20)*1.062,sind(10)*1.015,0];
plot(H_up,M_up)
hold on
plot(H_lo,M_lo)
I would like to fill space between those lines with some color, say light-blue. How to do that?
Thanks,
Lukasz

Best Answer

Try this:
H_up = [0,cosd(80)*7.387/10,cosd(70)*7.985/10,cosd(60)*8.906/10,cosd(50)*1.025,cosd(40)*1.238,cosd(30)*1.155,cosd(20)*1.064,cosd(10)*1.015,1];
H_lo = [0,cosd(80)*7.243/10,cosd(70)*7.826/10,cosd(60)*8.734/10,cosd(50)*1.009,cosd(40)*1.218,cosd(30)*1.137,cosd(20)*1.062,cosd(10)*1.015,1];
M_up = [7.021/10,sind(80)*7.387/10,sind(70)*7.985/10,sind(60)*8.906/10,sind(50)*1.025,sind(40)*1.238,sind(30)*1.155,sind(20)*1.064,sind(10)*1.015,0];
M_lo = [6.897/10,sind(80)*7.243/10,sind(70)*7.826/10,sind(60)*8.734/10,sind(50)*1.009,sind(40)*1.218,sind(30)*1.137,sind(20)*1.062,sind(10)*1.015,0];
plot(H_up,M_up)
hold on
plot(H_lo,M_lo)
patch([H_up fliplr(H_lo)], [M_up fliplr(M_lo)], [0.6 0.8 1.0])
hold off
See the documentation on the patch (link) function to understand how it works.