Borrar filtros
Borrar filtros

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

22 visualizaciones (últimos 30 días)
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 comentarios
Amit A
Amit A el 18 de Mayo de 2023
how to create a column vector named srcBits containing 20,000 randomly-generated bits.
Image Analyst
Image Analyst el 18 de Mayo de 2023
@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.

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 26 de Oct. de 2016
randi([-40,40],n,1)

Star Strider
Star Strider el 26 de Oct. de 2016
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)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by