making a matrice with conditions

조회 수: 1 (최근 30일)
Jens Petit-jean
Jens Petit-jean 2020년 11월 14일
댓글: Jens Petit-jean 2020년 11월 14일
Hello,
I have a column variable with 20 random numbers between 0 and 19. How do I add +2 to all numbers but the numbers can be maximum 20?
Thanks in advance

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 11월 14일
편집: Ameer Hamza 2020년 11월 14일
You can use min()
x = randi([0 19], 1, 20);
y = min(x+2, 20);
  댓글 수: 3
John D'Errico
John D'Errico 2020년 11월 14일
You use min, because you want MATLAB to take the SMALLER of x+2 and 20. Ergo, min.
Jens Petit-jean
Jens Petit-jean 2020년 11월 14일
ah thanks!

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

추가 답변 (0개)

카테고리

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