How do I create a column vector of random numbers between -40 and 40, with "n" entries?

30 次查看(过去 30 天)
I know rand returns random values between 0 and 1 and randi returns random integers, but how do I create a column vector with random numbers within a certain range?
  2 个评论
Image Analyst
Image Analyst 2023-5-18
@Amit A, start your own question in a new thread, and there say how many elements you want in the vector and how many bits are in each number/element of the vector.

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2016-10-26
randi([-40,40],n,1)

Star Strider
Star Strider 2016-10-26
If you want random floating-point numbers:
n = 1000; % Pick A Number
rv = 80*rand(n,1)-40; % Vector Of Random Floating-Point Numbers
figure(1)
hist(rv,50) % Check Result (Optional)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by