MATLAB: How to fill area above a plot

areafillMATLABplot

Hello, I am trying to fill the area above a curve in my top subplot. I have already filled the area beneath my lower curve but cannot seem to get the area above the upper curve. Both curves are create from sets of data points.
ax1 = subplot(2,1,1);
plot(Freq1,Gain_Upper)
hold on
basevalue = -15;
ar=area(Freq2,Gain_Lower,basevalue);
Hz vs dB.PNG

Best Answer

Try this:
x = 0:10:90; % Create Data


G1 = [-1 -2 -3 -4 -5 -7 -9 -11 -12 -13]; % Create Data
G2 = [1 1 2 2 2 2 2 2 2 2]; % Create Data
figure
plot(x, G2)
axis([0 100 -15 5])
hold on
plot(x, G1)
patch([x fliplr(x)], [G1 min(ylim)*ones(size(G1))], 'r') % Below Lower Curve
patch([x fliplr(x)], [G2 max(ylim)*ones(size(G2))], 'r') % Above Upper Curve
hold off
grid
How can I fill area above a plot - 2019 05 15.png
Experiment to get the result you want.