小工具知识网

当前位置: 首页 > 行业知识 > matlab 绘制正态分布图

行业知识

matlab 绘制正态分布图

2026-11-09 21:14:26 来源:互联网转载

目录

  • 一、简单正态分布曲线
    • 1、代码实现
    • 2、结果展示
    • 二、绘制不同分布区间的颜色
      • 1、代码实现
      • 2、结果展示
      • 三、计算标准差分布的百分比
        • 1、代码实现
        • 2、结果展示

          本文由CSDN点云侠原创,原文链接。如果你不是在点云侠的博客中看到该文章,那么此处便是不要脸的爬虫与GPT。

          一、简单正态分布曲线

          1、代码实现

          % 生成符合标准正态分布的随机数data = randn(10000, 1);% 计算平均值和标准差mu = mean(data);sigma = std(data);% 绘制标准正态分布曲线x = linspace(mu - 4*sigma, mu + 4*sigma, 100);y = normpdf(x, mu, sigma);plot(x, y, 'LineWidth', 2);hold on;% 在x轴上标示出距离平均值位置的1倍、2倍和3倍标准差值位置line([mu-sigma, mu-sigma], [0, normpdf(mu-sigma, mu, sigma)], 'Color', 'r', 'LineStyle', '--');line([mu+sigma, mu+sigma], [0, normpdf(mu+sigma, mu, sigma)], 'Color', 'r', 'LineStyle', '--');line([mu-2*sigma, mu-2*sigma], [0, normpdf(mu-2*sigma, mu, sigma)], 'Color', 'g', 'LineStyle', '--');line([mu+2*sigma, mu+2*sigma], [0, normpdf(mu+2*sigma, mu, sigma)], 'Color', 'g', 'LineStyle', '--');line([mu-3*sigma, mu-3*sigma], [0, normpdf(mu-3*sigma, mu, sigma)], 'Color', 'b', 'LineStyle', '--');line([mu+3*sigma, mu+3*sigma], [0, normpdf(mu+3*sigma, mu, sigma)], 'Color', 'b', 'LineStyle', '--');

          2、结果展示

          二、绘制不同分布区间的颜色

          1、代码实现

          % 设置图形属性xlabel('x');ylabel('Probability Density');title('Standard Normal Distribution');legend('Standard Normal Distribution', '1\sigma', '2\sigma', '3\sigma');x = -4:0.01:4; % x轴范围y = normpdf(x, 0, 1); % 标准正态分布的概率密度函数plot(x, y, 'b', 'LineWidth', 2); % 绘制蓝色曲线hold on; % 保持图形窗口,以便后续添加标记和区域mean_value = 0; % 平均值std_value = 1; % 标准差% 计算距离平均值位置的1倍、2倍和3倍标准差值x1 = mean_value - std_value;x2 = mean_value - 2 * std_value;x3 = mean_value - 3 * std_value;x4 = mean_value + std_value;x5 = mean_value + 2 * std_value;x6 = mean_value + 3 * std_value;% 绘制标记plot([x1, x1], [0, normpdf(x1, 0, 1)], 'r--', 'LineWidth', 1); %1倍标准差位置,红色虚线plot([x2, x2], [0, normpdf(x2, 0, 1)], 'g--', 'LineWidth', 1); % 2倍标准差位置,绿色虚线plot([x3, x3], [0, normpdf(x3, 0, 1)], 'm--', 'LineWidth', 1); % 3倍标准差位置,品红色虚线plot([x4, x4], [0, normpdf(x4, 0, 1)], 'r--', 'LineWidth', 1); % 1倍标准差位置,红色虚线plot([x5, x5], [0, normpdf(x5, 0, 1)], 'g--', 'LineWidth', 1); % 2倍标准差位置,绿色虚线plot([x6, x6], [0, normpdf(x6, 0, 1)], 'm--', 'LineWidth', 1); % 3倍标准差位置,品红色虚线% 绘制不同分布区间的颜色area(x(xx6), 'FaceColor', [0.9 0.9 0.9]); % 平均值右侧区域,浅灰色area(x(x>=x1 & x=x1 & xx4 & xx4 & xx5 & xx5 & x

上一篇:phira怎么搭建服务器?

下一篇:vue报错:We‘re sorry but doesn‘t work properly without JavaScript enabled. Please enable it to continue