MATLAB: To roll a dice simulator

dicediegamblingMATLABprobabilityrandomrolling

I'm trying to create a dice simulator using MATLAB. I have to use the function input and output to create a loop. We let K be the integer from 1 to 6 that represents the number we want to see from the die. We let n be the integer that represent the number of rolls for the first K to appear from the die. We can use the randi function.
This is what I have so far:
numberOfExperiments = 6; %I know that is our n or the number of rolls%
numberOfDice = 1;
rollValues = randi(6, [numberOfDice, numberOfExperiments])
I'm trying to connect that with this:
function [n] = firstRollK(K)
% code
end

Best Answer

One way to approach this (and the one that seems most compatible with your homework assignment) is to use a while loop with an internal counter ‘n’ that keeps rolling the die (and increments) until ‘k’ appears. The loop then stops and reports ‘n’.