making a matrice with conditions
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
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
2020년 11월 14일
You use min, because you want MATLAB to take the SMALLER of x+2 and 20. Ergo, min.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!