MATLAB: Plot pdf from histogram – dice

dicediehistogrampdfprobabilityprobability density functionrandom

I set up my histogram:
AllRoll = randi(6,50000, 1);
SumRoll = sum(AllRoll, 2);
Bins = (1:6);
hist(SumRoll,Bins);
title(sprintf('Histogram'));
xlabel(sprintf('1-6'));
ylabel(sprintf('number of rolls'));
grid on
hold on
I'm trying to turn this into a pdf. I know I have to bring down the values so that it can equal 1, but I'm not sure what I'm dividing and multiplying and summing here.

Best Answer

hist function is not recommended. Please use histogram function instead.
And by setting the 'Normalization' option, PDF can be plotted, like:
AllRoll = randi(6,50000, 1);
SumRoll = sum(AllRoll, 2);
Edges = 0.5:1:6.5;
histogram(SumRoll,Edges,'Normalization','probability');
title(sprintf('PDF'));
xlabel(sprintf('1-6'));
ylabel(sprintf('Probability'));
grid on
hold on
Related Question