我必须编写一个脚本,该脚本使用用户输入来掷一定数量的骰子、一定数量的边数、一定数量的掷骰和一定数量的试验。
我有整个用户输入部分,但我在编写掷骰子的函数时遇到了麻烦。
function [ X ] = Dice( N, S, T, R )
% Dice simulates a random selection of numbers which is similar to how a
% dice is rolled
% N is the number of dice the user wants to roll
% S is the number of sides on the dice
% T is the number of trials that the user wants to run.
% R is the number of rolls that the user wants to roll each dice.
D =ceil(S*rand(1,N))
% I used this for one roll of the dice
Counts = hist(D,[1:S]);
% Then I used this to count how many of each number showed up
如何编写代码以便我可以考虑试验和滚动的数量?我知道我可能不得不对 for 循环做一些事情,但我很困惑,目前我什么都想不出来。