在Matlab中使用rand产生极限之间的数字 [英] Using rand in matlab to produce numbers between limits

查看:74
本文介绍了在Matlab中使用rand产生极限之间的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
在那里Matlab中使用伪数字生成器生成特定范围内数字的一种方法?

Possible Duplicate:
Is there a way in Matlab using the pseudo number generator to generate numbers within a specific range?

我想获得-10到10之间的20个随机整数,并且想到了在matlab中使用rand函数.

I want to get 20 random integer numbers between -10 and 10 and I thought of using the rand function in matlab.

我想到了十乘,然后找到一种方法来仅获取-10到10之间的数字,并对超出限制[-10,10]的其他每个数字使用迭代来获取新数字在限制之内.

I thought of myltiplying by ten and then finding a way to get only the ones between -10 and 10 and use an iteration for each of the other numbers that is outside the limits [-10,10] to get a new number inside the limits.

有没有更好,更快的方法?

Is there a better, faster way?

推荐答案

使用

randomIntegers = randi([-10,10],[20,1])

生成一个介于-10和10之间的随机整数的向量.

to generate a vector of random integers between -10 and 10.

这篇关于在Matlab中使用rand产生极限之间的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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