Random complete and in complete numbers

1 Ansicht (letzte 30 Tage)
Stephanie khoury
Stephanie khoury am 8 Mai 2020
Kommentiert: Matt J am 8 Mai 2020
I have tried using Randi function,but it only gives me complete numbers.also tried rand but it doesn't give me to choose a specific range. Is there a function in matlab that would give me both complete and incomplete numbers in a specific range?I need to put this numbers in a matrix

Akzeptierte Antwort

Matt J
Matt J am 8 Mai 2020
Bearbeitet: Matt J am 8 Mai 2020
To randomize uniformly over an interval [lower, upper], you would do,
out=rand(___)*(upper-lower)+lower
  6 Kommentare
Stephanie khoury
Stephanie khoury am 8 Mai 2020
Thank you so much?
Matt J
Matt J am 8 Mai 2020
that only gives complete numbers
No, you can use randi to generate any range of integers, not just the whole numbers. For example,
>> A=randi([-9,-7],5,4)
A =
-7 -7 -8 -7
-8 -7 -7 -7
-7 -9 -9 -8
-8 -7 -7 -9
-9 -8 -8 -7

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Steven Lord
Steven Lord am 8 Mai 2020
See the "Random Numbers Within Specified Interval" example on the documentation page for the rand function.
doc rand

Kategorien

Mehr zu Creating and Concatenating Matrices 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!

Translated by