How to create a random 3D matrix?

后端 未结 2 539
暗喜
暗喜 2021-01-18 15:46

Is there any way of creating a 3D matrix randomly? There are ways to create random 2D matrices using randint function. Is there any inbuilt function like that?

E.g.

2条回答
  •  终归单人心
    2021-01-18 16:02

    If you read the help carefully, you will notice that the randi function accepts any number of dimensions. You may do randi(10,3,3,3)

    randi(10,3,3,3)
    
    ans(:,:,1) =
    
         9    10     3
        10     7     6
         2     1    10
    
    
    ans(:,:,2) =
    
        10    10     2
         2     5     5
        10     9    10
    
    
    ans(:,:,3) =
    
         8     1     7
        10     9     8
         7    10     8
    

提交回复
热议问题