how to generate 100 random numbers between 5 and -5?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
if i use rand it gives me that "Index exceeds the number of array elements"
0 comentarios
Respuestas (1)
Jesús Zambrano
el 3 de Jun. de 2021
Hey Rayhan,
You can try with these lines of code:
a = -5;
b = 5;
N = 100;
r = a + (b-a).*rand(N,1);
Hope it helps!
3 comentarios
Steven Lord
el 30 de Oct. de 2023
Most likely, if you receive the error given in the original question, you've defined a variable named rand that prevents MATLAB from calling the rand function. To check, what does this show?
which rand
If you have a variable with that name, you'd see this instead:
rand = 42;
which rand
Clear the variable and modify your code (if necessary) to avoid creating a variable of that name.
Ver también
Categorías
Más información sobre Random Number Generation 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!