-1

我必须编写一个脚本,该脚本使用用户输入来掷一定数量的骰子、一定数量的边数、一定数量的掷骰和一定数量的试验。

我有整个用户输入部分,但我在编写掷骰子的函数时遇到了麻烦。

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 循环做一些事情,但我很困惑,目前我什么都想不出来。

4

1 回答 1

1

结果矩阵=兰迪(S,N,R,T)

这将为每个试验创建一组“T”矩阵(第一个矩阵是第一个试验等),每个矩阵都有“R”列用于每个滚动(第 1 列是第 1 滚动等),每个骰子都有“N”行滚动(第 1 行是模具 1,等等)。当然,这些值从 1:S 开始,代表滚动的结果。

于 2011-06-30T17:48:05.030 回答