How to generate a matrix of random integers from 55 to 100?
96 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yuval
am 27 Mär. 2013
Kommentiert: Carlos Flores
am 25 Sep. 2022
Using function rand, should a matrix of random integers in the interval [55..100] be generated thus:
M = ceil((rand(5,5)+(11/9))*45);?
0 Kommentare
Akzeptierte Antwort
the cyclist
am 27 Mär. 2013
Bearbeitet: the cyclist
am 27 Mär. 2013
That looks right if you have to use rand(), for example if this is a school assignment.
Easier would be
M = randi([55 100],5,5);
2 Kommentare
Weitere Antworten (2)
Pranali Navale
am 14 Apr. 2021
m=rand([1 20],5,5)
2 Kommentare
Steven Lord
am 14 Apr. 2021
No, that will not work. The randi function accepts as its first input a range to control how large or small the generated random integer values can be. The rand function does not.
m = rand([1 20], 5, 5);
See the examples in the documentation for rand if you want to generate random values (not necessarily integer values) between 1 and 20.
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!