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

181 次查看(过去 30 天)
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);?

采纳的回答

the cyclist
the cyclist 2013-3-27
编辑:the cyclist 2013-3-27
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 个)

Pranali Navale
Pranali Navale 2021-4-14
m=rand([1 20],5,5)
  2 个评论
Steven Lord
Steven Lord 2021-4-14
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.

请先登录,再进行评论。


Luis Freitas
Luis Freitas 2022-2-22
ceil((rand(5,5)+(11/9))*45)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by