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

采纳的回答

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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by