Reputation: 27
How can i plot a uniform density over a histogram using histfit()? There's a command to do it for the normal distribution and a few others so do i have to manipulate one of them to get uniform?
example:
s4 = randn(50,1);
counts = [];
[counts(1,:) freq] = histc(s4, [-inf,-3]);
for n = 2:7
[counts(n,:) freq] = histc(s4, [-5+n,-4+n]);
end
[counts(8,:) freq] = histc(s4, [3,inf]);
counts(1:8)
histfit(s4).
How can i implement a histfit for a uniform histogram?
s = rand(50,1);
[count freq]= hist(s,5);
histfit(s);
count
Upvotes: 2
Views: 1138
Reputation: 340
If all you want is a horizontal line on top of the histogram to look like the example you gave, try:
s4 = randn(50,1);
[N,X] = hist(s4,sqrt(numel(s4)));
bar(X,N);
hold on
plot([min(s4) max(s4)],[mean(N),mean(N)],'r','LineWidth',2);
This gives me a histogram, with a horizontal line at the mean of the bin values.
Upvotes: 1