making matrices with conditions

2 ビュー (過去 30 日間)
Jens Petit-jean
Jens Petit-jean 2020 年 11 月 14 日
コメント済み: Jens Petit-jean 2020 年 11 月 14 日
hello,
1) How do I make a 6x5 matrice with even whole numbers between 20 and 100 (with 20 and 100 included)
2)How do I make a 6x5 matrice with different whole numbers between 20 and 100
thank you in advance

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 14 日
Are you trying to make a matrix with random elements? If yes, then try randi()
lb = 20;
ub = 100;
M_even = randi([lb ub]/2, 6, 5)*2;
M_whole = randi([lb ub], 6, 5);
  4 件のコメント
Ameer Hamza
Ameer Hamza 2020 年 11 月 14 日
Bruno's answer using randperm() is easiest and probably most efficient, but if you have Statistics and ML toolbox, you can also try randsample()
M_whole = randsample(20:100, 30, false);
M_whole = reshape(M_whole, [6, 5])
Jens Petit-jean
Jens Petit-jean 2020 年 11 月 14 日
okay thank you very much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by