如何规范化直方图

时间:2015-10-15 11:37:54

标签: matlab plot histogram distribution

我可以使用逆方法创建指数分布。我想规范化直方图。我该怎么办?

这是我的代码

var appPath = ConfigurationManager.AppSettings["configPath"].ToString();
            string configFile = System.IO.Path.Combine(appPath, "App.config");
            var configFileMap = new ExeConfigurationFileMap();
            configFileMap.ExeConfigFilename = configFile;
            System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap, ConfigurationUserLevel.None);

 config.AppSettings.Settings["InvoiceInterval"].Value = InvoiceIntervalVal.ToString();

1 个答案:

答案 0 :(得分:2)

应将柱状图归一化为单位面积,以便将其与理论pdf进行比较。要标准化为单位面积,您需要除以样本数和二进制宽度:

N = 100;
Lambda=2;
r = rand(N,1);
X = -log(1-r)/Lambda;
[hy, hx] = hist(X); %/ get histogram values
hy = hy/numel(X)/(hx(2)-hx(1)); %//normalize histogram
bar(hx, hy) %// plot histogram
t = 0:0.01:5;
pdf = Lambda*exp(-Lambda*t);
hold on, plot(t,pdf,'LineWidth',2) %// plot pdf

enter image description here

或者使用新的histogram函数(在R2014b中引入),根据指定的规范化选项自动规范化

N = 100;
Lambda=2;
r = rand(N,1);
X = -log(1-r)/Lambda;
histogram(X, 'Normalization', 'pdf') %// plot normalized histogram
t = 0:0.01:5;
pdf = Lambda*exp(-Lambda*t);
hold on, plot(t,pdf,'LineWidth',2) %// plot pdf