How do I plot confidence intervals in MATLAB?

前端 未结 3 1870
半阙折子戏
半阙折子戏 2021-01-14 17:36

I want to plot some confidence interval graphs in MATLAB but I don\'t have any idea at all how to do it. I have the data in a .xls file.

Can someone give me a hint,

3条回答
  •  悲&欢浪女
    2021-01-14 18:06

    I'm not sure what you meant by confidence intervals graph, but this is an example of how to plot a two-sided 95% CI of a normal distribution:

    alpha = 0.05;          % significance level
    mu = 10;               % mean
    sigma = 2;             % std
    cutoff1 = norminv(alpha, mu, sigma);
    cutoff2 = norminv(1-alpha, mu, sigma);
    x = [linspace(mu-4*sigma,cutoff1), ...
        linspace(cutoff1,cutoff2), ...
        linspace(cutoff2,mu+4*sigma)];
    y = normpdf(x, mu, sigma);
    plot(x,y)
    
    xlo = [x(x<=cutoff1) cutoff1];
    ylo = [y(x<=cutoff1) 0];
    patch(xlo, ylo, 'b')
    
    xhi = [cutoff2 x(x>=cutoff2)];
    yhi = [0 y(x>=cutoff2)];
    patch(xhi, yhi, 'b')
    

    plot

提交回复
热议问题