-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
我該如何編寫代碼,以便能夠計算試用和滾動的數量?我知道我可能不得不爲循環做些事情,但我很困惑,現在我什麼也想不到。
這是功課嗎?如果是這樣,你可能會重新標記你的問題。謝謝 – eat 2011-03-10 08:44:13
你可能想看看[現有的代碼](http://www.mathworks.com/matlabcentral/fileexchange/27327-a-dice-roller-for-matlab)骰子滾筒。 – Jonas 2011-03-10 14:43:06