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

조회 수: 24 (최근 30일)
Yuval
Yuval 2013년 3월 27일
댓글: Carlos Flores 2022년 9월 25일
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.
Nikunj Aswani
Nikunj Aswani 2022년 2월 5일
use randi instead of rand

댓글을 달려면 로그인하십시오.


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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by