Trying to create an m x n (n=2 columns) matrix where n is incremented in integers starting with 1 and the second column outputs a random integer from 1 to 6 as if 1 die were being thrown n times.
1 次查看(过去 30 天)
显示 更早的评论
Is there a better was to achieve the results of the following code without having to re-type the row and column elements 5 times?
dieRolls5 = [1,(randi ([1,6]));2,(randi ([1,6]));3,(randi ([1,6]));4,(randi ([1,6]));5,(randi ([1,6]));]
The results are correct but one must do a lot of manual work to simulate the results of a different number of throws of the die.
One might want to create a matrix with a different number of throws of the die; e.g., 8 throws. Having to type the following code is obviously not a good solution.
diceRoll8 = [1,(randi ([1,6]));2,(randi ([1,6]));3,(randi ([1,6]));4,(randi ([1,6]));5,(randi ([1,6]));6,(randi ([1,6]));7,(randi ([1,6]));8,(randi ([1,6]));]
0 个评论
采纳的回答
更多回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operators and Elementary Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!