【发布时间】:2017-01-26 15:46:47
【问题描述】:
我在 MatLab 中被赋予了创建一个程序的任务:
- 模拟滚动两个 6 面模具 N 次的实验,将滚动的 2 个值相加,然后绘制获得这些值的频率。
- 然后能够打印滚动结果中最频繁和最不频繁之间的百分比差异。
我已经想出了第一部分的方法:
numberOfDice = 2; %Number of dice to be rolled
numberOfDots = 6; %Number of max. dots allowed on a die face
numberOfRolls = 100000; %Number of times the die(s) are rolled
%#Generate the rolls and obtain the sum of the rolls
AllRoll = randi(numberOfDots, numberOfRolls, numberOfDice);
sumOfRoll = sum(AllRoll, 2);
%#Determine the bins for the histogram
Bins = (numberOfDice:numberOfDots * numberOfDice)';
%#Build the histogram
hist(sumOfRoll, Bins);
title(sprintf('The Frequency of Different Sums from %d %d-sided Dice after %d Rolls', numberOfDice, numberOfDots, numberOfRolls));
xlabel(sprintf('The Sum of %d Dice', numberOfDice));
ylabel('Count');
我不知道如何实现第二部分,因为我不确定如何从我的直方图中获取最大值和最小值。这甚至可能吗,还是我必须以另一种方式去做?我很迷茫。任何帮助都会很棒。
【问题讨论】:
-
1) 不要使用
hist,histogram在现代版本的matlab 中是首选。 2) 看看histcounts。
标签: matlab max histogram minimum