MATLAB: I keep getting the error index exceeds the number of array elements(1)

collegeerrorforfor loophelphomeworklogicalsMATLABsolution

roll = zeros(1,300);
for i = 1:300
dice = 1 + ceil(11*rand(1));
end
freeornah = roll+dice(i)
freeornah = roll+dice(i)I keep getting the error index exceeds the number of array elements(1). I am trying to add each number in the column vector roll with each dice roll. Then I'm trying to create a logical where if the number I receive for freeornah is true if it is either 11 or 12.

Best Answer

The problem is that dice is completely changed in each loop.
In this case, roll is meaningless.
dice = zeros(1,300);
for i = 1:300
dice(i) = 1 + ceil(11*rand(1));
end
freeornah = dice==11|dice==12;