Normalized distribution for histogram
12 views (last 30 days)
Dimuthu Dharshana on 9 Oct 2013
I want to obtain the normalized curve for the following program on the same histogram curve.
Kindly help me.
DailyaverageData = xlsread('exceltomatlab.xlsx','Sheet1', 'B2:B2290');
n = length(DailyaverageData);
binranges = 0:0.1:1;
binCtrs = 0.05:0.1:0.95;
counts = hist(DailyaverageData,binCtrs);
[bincounts] = histc(DailyaverageData,binranges);
prob = counts /n;
%H = bar(binranges,bincounts/n,'histc');
H = bar(binCtrs,prob,'hist');
Jonathan LeSage on 16 Oct 2013
Edited: Jonathan LeSage on 16 Oct 2013
If you have the Statistics Toolbox, you might find the dfittool distribution fitting tool quite useful.
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
histHandle = bar(binCenters,binCount/probScale,'hist');
% Overlay the distribution fit on the histogram
x = binCenters;
y = normpdf(x,muData,stdData);
Hope this helps to get you started!