MATLAB: How to shade an area of the graph between two vertical lines

graphplotshade

Hello, I am trying to shade an area under the curve of a lognormal pdf between two vertical lines. Here is the code to help you generate the problem:
pd = makedist('Lognormal','mu',3.323167914007358,'sigma',0.241878609884653)
r = random(pd,1000,1); % generate 1000 numbers from the distribution
ix = linspace(min(r),max(r)); % to scale the graph
y = pdf(pd, ix);
figure
plot(ix,y)
hold on;
line([20, 20], ylim, 'LineWidth', 2, 'Color', 'r');
hold on;
line([24, 24], ylim, 'LineWidth', 2, 'Color', 'r');
This is the picture of the plot above:
I tried searching, but the best answer I have come up with fills the area between the lines all the way to the top of the graph, while I want it to end at the curve. Also, I want the lines to stop at the curve, not stretch beyond it. Here is a google picture of what I am trying to achieve:

Best Answer

iz=linspace(20,24,40);
yz=pdf(pd,iz);
area(iz,yz)