Plot pdf from histogram - dice

20 ビュー (過去 30 日間)
Mel Hernandez
Mel Hernandez 2018 年 1 月 30 日
回答済み: Akira Agata 2018 年 11 月 25 日
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.

採用された回答

Akira Agata
Akira Agata 2018 年 2 月 5 日
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
  1 件のコメント
jyoti mundra
jyoti mundra 2018 年 11 月 23 日
why cannot we use pdf value for normalisation property of histogram. What it will give?

サインインしてコメントする。

その他の回答 (1 件)

Akira Agata
Akira Agata 2018 年 11 月 25 日
You can set 'Normalization' option of histogram function to 'pdf', like:
histogram(SumRoll,Edges,'Normalization','pdf');
If you want to obtain pdf value for each pip of a die, you can use histcount function.
p = histcounts(SumRoll,Edges,'Normalization','pdf');
The result is as follows:
>> p
p =
0.1649 0.1683 0.1640 0.1688 0.1681 0.1659

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by