MATLAB: Plot multiple normal distributions on a single figure, using normspec()

MATLABmultiple plotsnormal distributionnormspecplot

Hello,
I want to plot two normal distributions on the same figure using the normspec () command. The problem is that Matlab always creates two separate figures, even if I use the "hold on" command. Is there a way to get around this problem?
I'd appreciate any help!
Best, Martin

Best Answer

I did this a couple months ago with this code:
alpha = 0.05; % significance level
mu = 82.9; % mean
sigma = 8.698; % std
x = linspace(mu-5*sigma, mu+5*sigma, 500);
cutoff1 = norminv(alpha/2, mu, sigma); % Lower 95% CI is p = 0.025
cutoff2 = norminv(1-alpha/2, mu, sigma); % Upper 95% CI is p = 0.975
y = normpdf(x, mu, sigma);
xci = [linspace(mu-5*sigma, cutoff1); linspace(cutoff2, mu+5*sigma)];
yci = normpdf(xci, mu, sigma);
figure(1)
plot(x, y, '-b', 'LineWidth', 1.5)
patch(x, y, [0.5 0.5 0.5])
patch([xci(1,:) cutoff1], [yci(1,:) 0], [1 1 1])
patch([cutoff2 xci(2,:)], [0 yci(2,:)], [1 1 1])
Experiment with it until you get the result you want. As written, it produces: