MATLAB: Creating a random game of dice

ceildicefor loopmonte carlo

This is what I have to do
disp('You are going to throw a dice and get the total for 5 tries')
de=[0 0 0 0 0]
for de(1,1)=ceil(rand*6);
disp(de(1))
end
And you do the same thing for each try
But it keeps giving me an error

Best Answer

A for loop needs an index variable and a set of values to loop through. Check out the documentation here. It has the form:
for index = values
program statements
:
end
I suspect you mean to do something like this:
disp('You are going to throw a dice and get the total for 5 tries')
de=[0 0 0 0 0]
for i = 1:6;
de(i) = ??? % your code here
disp( de(i) )
end
Pay careful attention to the de(i) syntax. We use de(i) instead of de(1), so that in the first run through of the loop we are working with de(1), in the second run through we get de(2) and so on all the way up to de(6).