Matlab,包含指定范围内随机数的矩阵 [英] Matlab, matrix containing random numbers within specified range
问题描述
我对 Matlab 完全陌生,正在尝试创建一个 m×n 矩阵,其中包含指定范围内(即 -1 和 1 之间)的数字.
I am absolutely new to Matlab and am trying to create an m-by-n matrix containing numbers within a specified range (ie. between -1 and 1).
是否有与 rand(m, n)
等效的函数,我可以在其中自己指定范围,或者我是否需要明确地创建一堆随机数(如本answer) 并从它们创建一个矩阵?
Is there an equivalent function to rand(m, n)
where I can specify the range myself or would I need to explicitely create a bunch of random numbers (as ie. was described in this answer) and create a matrix from them?
任何指向相关文档等的指针,高度赞赏.
Any pointers to relevant Documentation, etc. highly appreciated.
推荐答案
这直接来自 Matlab 的 rand
文档.这是你想要的吗?
This is straight from Matlab's documentation for rand
. Is this want you want?
示例 1
从区间 [a, b] 上的均匀分布生成值:
Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);
尝试通过在命令窗口中输入 doc rand
来阅读 Matlab 文档.它非常有用且用户友好.
Try reading the Matlab documentation by entering doc rand
in the command window. It is really informative and user friendly.
这篇关于Matlab,包含指定范围内随机数的矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!