Generating random numbers using for loop
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Maheen Fazal
am 7 Feb. 2019
Beantwortet: Image Analyst
am 18 Jun. 2022
Hi, Shall i use the following code to generate random numbers and use them further in the calculation?
clear all
close all
for n=1:2;
h(n)=rand
end
Akzeptierte Antwort
Walter Roberson
am 7 Feb. 2019
If you like. you could instead pass size information to rand to say how many items to generate .
Weitere Antworten (2)
Image Analyst
am 18 Jun. 2022
@Maheen Fazal did you look at the help? If you would, you'd see info like this:
Random Numbers Within Specified Interval
Generate a 10-by-1 column vector of uniformly distributed numbers in the interval (-5,5).
r = -5 + (5+5)*rand(10,1)
So, for you:
h = rand(1, 2)
0 Kommentare
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!