MATLAB Answers

how to generate 100 random numbers between 5 and -5?

2 views (last 30 days)
rayhan hindi
rayhan hindi on 3 Jun 2021
Commented: rayhan hindi on 3 Jun 2021
if i use rand it gives me that "Index exceeds the number of array elements"

Answers (1)

Jesús Zambrano
Jesús Zambrano on 3 Jun 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!

Community Treasure Hunt

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

Start Hunting!