如何创建随机3D矩阵? [英] How to create a random 3D matrix?
本文介绍了如何创建随机3D矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法随机创建3D矩阵?有多种方法可以使用 randint
函数.有这样的内置功能吗?
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?
例如使用randint
函数可以轻松生成4x4矩阵.如果我要创建尺寸为4x4x3的矩阵怎么办?
E.g. a 4x4 matrix can be generated easily by using the randint
function. What if I want to create a matrix of dimension 4x4x3?
推荐答案
您可以使用 randi(imax, size1, size2, size3)
函数,其中imax
是指随机整数值的最大值(平均上限),而1
是下限.您可以将size
参数扩展为所需的sizeN
.
You can use randi(imax, size1, size2, size3)
function where imax
refers to maximum of random integer values (mean upper bound) and 1
is lower bound. You can expand size
argument to sizeN
what you want.
这是其用法示例:
>> A = randi(5, 4, 4, 3)
A(:,:,1) =
4 4 5 4
4 1 2 2
2 1 3 3
4 3 2 4
A(:,:,2) =
5 1 5 1
5 2 2 2
3 5 5 4
1 2 2 3
A(:,:,3) =
2 5 2 3
5 2 3 4
3 4 1 5
3 4 1 1
这篇关于如何创建随机3D矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文