Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

histfit

205 views
Skip to first unread message

Stefan

unread,
Mar 30, 2004, 8:56:18 AM3/30/04
to
Hi!

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');

Peter Perkins

unread,
Apr 6, 2004, 1:55:04 PM4/6/04
to
> 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.

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.

Stefan

unread,
Apr 14, 2004, 6:01:19 AM4/14/04
to
Hi Peter!

I have tried to use normpdf, but I haven´t solved it.
Thanks for your time,
Stefan

Peter Perkins

unread,
Apr 14, 2004, 10:07:50 AM4/14/04
to
> I have tried to use normpdf, but I haven´t solved it.

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]);

0 new messages