フィルターのクリア

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]));]

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 25 日
N = 8;
dieRolls = [(1:N).', randi(6,N,1)];

その他の回答 (1 件)

John
John 2016 年 10 月 25 日
Thank you!

カテゴリ

Help Center および File ExchangeBuild Deep Neural Networks についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by