How to generate a matrix of random integers from 55 to 100?

188 visualizaciones (últimos 30 días)
Yuval
Yuval el 27 de Mzo. de 2013
Comentada: Carlos Flores el 25 de Sept. de 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);?

Respuesta aceptada

the cyclist
the cyclist el 27 de Mzo. de 2013
Editada: the cyclist el 27 de Mzo. de 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);

Más respuestas (2)

Pranali Navale
Pranali Navale el 14 de Abr. de 2021
m=rand([1 20],5,5)
  2 comentarios
Steven Lord
Steven Lord el 14 de Abr. de 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);
Error using rand
Size inputs must be scalar.
See the examples in the documentation for rand if you want to generate random values (not necessarily integer values) between 1 and 20.
Nikunj Aswani
Nikunj Aswani el 5 de Feb. de 2022
use randi instead of rand

Iniciar sesión para comentar.


Luis Freitas
Luis Freitas el 22 de Feb. de 2022
ceil((rand(5,5)+(11/9))*45)

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by