MATLAB: Shade area under a semilog plot

shade area under semilog curve

In the code below, I would like to shade the area between freq = 300 to freq = 3000:
freq = 100:1:10000;
pnoise = -60:-.01:-159;
subplot(1, 2, 1);
semilogx(freq,pnoise); grid on; axis([0 10^5 -160 -70]);
title('Original Plot');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
subplot(1, 2, 2);
H1=area(semilogx(freq,pnoise)); grid on; axis([0 10^5 -160 -70]);
hold on
title('Plot with Area Shaded');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
idx=freq>300&freq<3000;
H=area(freq(idx),pnoise(idx));
set(H(1),'FaceColor',[1 0.5 0]);
However, I am not getting the second plot to show up with the shaded region correctly. Any help is appreciated.

Best Answer

It took a bit of experimenting with the patch function. See if this does what you want:
freq = 100:1:10000;
pnoise = -60:-.01:-159;
subplot(1, 2, 1);
semilogx(freq,pnoise); grid on; axis([0 10^5 -160 -70]);
title('Original Plot');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
subplot(1, 2, 2);
semilogx(freq,pnoise)
hold on
title('Plot with Area Shaded');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
idx=freq>300&freq<3000;
minpnoise = pnoise(find(idx,1,'last'));
patch([300 freq(idx) 3000 300], [-160 pnoise(idx) -160 -160], [1 0.5 0]);
grid on; axis([0 10^5 -160 -70]);