Matlab,矩阵包含指定范围内的随机数 [英] Matlab, matrix containing random numbers within specified range

查看:526
本文介绍了Matlab,矩阵包含指定范围内的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对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)等效的功能,我可以在其中自行指定范围,或者需要显式创建一堆随机数(如

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆