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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!