I having a problem with histfit. I will have the values in percent for
y axis, but I haven´t succeed. For hist I have done it, but I when I
try with histfit it will not work.
Can someone help me with my problem?
The code are:
function graf = PrintGraf(IP)
packets=size(IP); %antal paket
m = mean(IP)
s = std(IP)
%The values are counted into percent and
%plotted with bar
[n, ctrs] = hist(IP, 50);
%[H] = histfit(IP, 20);
%% Histogram scaled to unit area
binwidth = ctrs(2)-ctrs(1)
pdfheight = n / (binwidth * sum(IP));
bar(ctrs, pdfheight, 'hist');
xlabel('Delay (ms)');
ylabel('Probability');
title('Burst length One');
%A new figure with histfit
figure
histfit(IP)
xlabel('Delay (ms)');
ylabel('Probability');
title('Burst length One');
Hi Stefan -
HISTFIT is designed to plot a histogram with counts, and not relative
frequency or probability. But it looks like you've already figured out the
hard part of how to make the plot that you want -- all you need to do now is
use normpdf to compute the normal PDF over the range of your data, turn hold
on, use plot to overlay the PDF curve on the bars, and turn hold off.
Alternatively, you can create your own version of HISTFIT, by deleting this line
y = row*(y*binwidth)
and dividing xbin by (row*binwidth) in this line
hh = bar(xbin,n,1);
Hope this helps.
- Peter Perkins
The MathWorks, Inc.
I have tried to use normpdf, but I haven´t solved it.
Thanks for your time,
Stefan
Stefan -
I think all you need is something like this:
IPgrid = linspace(min(IP),max(IP));
hold on
plot(IPgrid,normpdf(IPgrid,m,s));
hold off
It probably would not hurt to call bar with the FaceColor graphics parameter
to change the color of the bars to something lighter, so you can see the
density curve:
h = bar(...,'FaceColor',[.7 .7 .7]);