Normalized distribution for histogram

10 ビュー (過去 30 日間)
Dimuthu Dharshana
Dimuthu Dharshana 2013 年 10 月 9 日
コメント済み: Dimuthu Dharshana 2013 年 10 月 29 日
Hi,
I want to obtain the normalized curve for the following program on the same histogram curve.
Kindly help me.
clear all;
close all;
DailyaverageData = xlsread('exceltomatlab.xlsx','Sheet1', 'B2:B2290');
n = length(DailyaverageData);
binranges = 0:0.1:1;
binwidth=.1;
binCtrs = 0.05:0.1:0.95;
counts = hist(DailyaverageData,binCtrs);
[bincounts] = histc(DailyaverageData,binranges);
%figure;
%bar(binranges,bincounts/n,'histc');
%xlim([0 1]);
prob = counts /n;
%H = bar(binranges,bincounts/n,'histc');
H = bar(binCtrs,prob,'hist');

採用された回答

Jonathan LeSage
Jonathan LeSage 2013 年 10 月 16 日
編集済み: Jonathan LeSage 2013 年 10 月 16 日
If you have the Statistics Toolbox, you might find the dfittool distribution fitting tool quite useful.
doc dfittool
If not, you can normalize a histogram by scaling the counts in each bin. With the normalized counts, you can plot both the normalized histogram and your curve. The trick is to identify the appropriate scaling factor.
Here is some example code where I plot the normal probability with the normalized histogram data:
% Arbitrary data generation and statistics
dataVec = randn(1000,1);
muData = mean(dataVec);
stdData = std(dataVec);
% Defining the bin centers
binStep = 0.1;
binCenters = -5:binStep:5;
% Compute the histogram scaling factor. (If all histogram counts are in a
% single bin, the probability = 1)
binCount = histc(dataVec,binCenters);
probScale = sum(binCount)*binStep;
% Plot the normalized histogram and change the bar color for line
% visibility
histHandle = bar(binCenters,binCount/probScale,'hist');
set(histHandle,'FaceColor',[1,1,1]);
hold on;
% Overlay the distribution fit on the histogram
x = binCenters;
y = normpdf(x,muData,stdData);
plot(x,y);
xlabel('Data');
ylabel('Probability');
Hope this helps to get you started!
  1 件のコメント
Dimuthu Dharshana
Dimuthu Dharshana 2013 年 10 月 29 日
Hi, Thank you very much. I tried in that way. However the probability exceeds 1.0 in histogram. I can't find how to fit it.
clear all; close all; DA = xlsread('exceltomatlab.xls','Sheet1', 'B2:B2290'); muDA = mean(DA); stdDA = std(DA); binStep=0.1; binCenters = 0.05:binStep:0.95; % Compute the histogram scaling factor. (If all histogram counts are in a % single bin, the probability = 1) binCount = histc(DA,binCenters); probScale = sum(binCount)*binStep; % Plot the normalized histogram and change the bar color for line % visibility histHandle = bar(binCenters,binCount/probScale,'hist'); set(histHandle,'FaceColor',[0.5,0.5,0.5]); hold on; % Overlay the distribution fit on the histogram x = binCenters; y = normpdf(x,muDA,stdDA); plot(x,y); xlabel('Data'); ylabel('Probability');
I hv attached the excel file as well.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by