making matrices with conditions

조회 수: 1 (최근 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 CenterFile Exchange에서 Elementary Math에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by