Matlab中rand和rand表示什么意思
1个回答
2015-02-20
展开全部
rand产生0-1的均匀随机数,你可以输入命令help rand查看帮助文档,这是最佳的学习方式。
r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1). r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix. r = rand(m,n,p,...) or r = rand([m,n,p,...]) returns anm-by-n-by-p-by-... array. r = rand returns a scalar. r = rand(size(A)) returns an array the same size as A.
r = rand(..., 'double') or r = rand(..., 'single') returns an array of uniform values of the specified class.
Example 1
Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);
你这个就类似于这里的例1
首先,rand(1,10)会产生一个1*10的矩阵,矩阵元素是介于0-1之间的随机数,rand(1.10)-.5则会产生介于-0.5-0.5的随机数矩阵。5*(rand(1.10)-.5)则会产生介于 -2.5-2.5的随机矩阵
r = rand(n) returns an n-by-n matrix containing pseudorandom values drawn from the standard uniform distribution on the open interval (0,1). r = rand(m,n) or r = rand([m,n]) returns an m-by-n matrix. r = rand(m,n,p,...) or r = rand([m,n,p,...]) returns anm-by-n-by-p-by-... array. r = rand returns a scalar. r = rand(size(A)) returns an array the same size as A.
r = rand(..., 'double') or r = rand(..., 'single') returns an array of uniform values of the specified class.
Example 1
Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);
你这个就类似于这里的例1
首先,rand(1,10)会产生一个1*10的矩阵,矩阵元素是介于0-1之间的随机数,rand(1.10)-.5则会产生介于-0.5-0.5的随机数矩阵。5*(rand(1.10)-.5)则会产生介于 -2.5-2.5的随机矩阵
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询