Random number between two decimal numbers
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Evica Smilkoska
am 15 Apr. 2022
Kommentiert: Image Analyst
am 16 Apr. 2022
Hi, how can a generate random number between two decimal numbers? For example i want to generate array 24x1 and for each row i have different interval, for the first row the interval is 0.124 to 0.908 and for second row 0.325 to 0.846. The generated values cant be above or below the interval.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 15 Apr. 2022
intervalmins = [0.124, 0.325];
intervalmaxs = [0.908, 0.846];
output = rand(length(intervalmins), 1) .* (intervalmaxs(:) - intervalmins(:)) + intervalmins(:)
Weitere Antworten (1)
Image Analyst
am 15 Apr. 2022
Did you check the documentation. The second example is
Generate a 10-by-1 column vector of uniformly distributed numbers in the interval (-5,5).
r = -5 + (5+5)*rand(10,1)
2 Kommentare
Image Analyst
am 16 Apr. 2022
Strange, since it's essentially the same formula that you accepted in Walter's answer. You changed the numbers in the MATLAB example to what you wanted your range to be right? Either inside your loop or by setting up a vector with all the parameters in advance like Walter showed you.
I can't really say more since you never uploaded your code. But it sounds like you somehow got it working afterwards because you accepted an answer.
Siehe auch
Kategorien
Mehr zu Logical 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!