Size input must be scalar using rand to generate uniformly distributed numbers
4 次查看(过去 30 天)
显示 更早的评论
I want to generate a set of random numbers which contains 1000 uniformly distributed numbers on the interval [-1,1]. I am getting the error that input must be scalar.
my code:
a = rand(1000,[-1,1]);
Error:
Error using rand
Size inputs must be scalar.
0 个评论
采纳的回答
Ameer Hamza
2020-11-18
编辑:Ameer Hamza
2020-11-18
rand() does not accept the range of random values. It always generates values between 0 and 1. You need to rescale yourself.
lb = -1;
ub = 1;
a = rand(1000,1)*(ub-lb) + lb; % 1000x1 vector
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!