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

30 ビュー (過去 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 件のコメント
Joel Rodriguez
Joel Rodriguez 2020 年 3 月 30 日
great
Carlos Flores
Carlos Flores 2022 年 9 月 25 日
Thank you it was very helpful!

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by