making a matrice with conditions

1 vue (au cours des 30 derniers jours)
Jens Petit-jean
Jens Petit-jean le 14 Nov 2020
Commenté : Jens Petit-jean le 14 Nov 2020
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

Réponse acceptée

Ameer Hamza
Ameer Hamza le 14 Nov 2020
Modifié(e) : Ameer Hamza le 14 Nov 2020
You can use min()
x = randi([0 19], 1, 20);
y = min(x+2, 20);
  3 commentaires
John D'Errico
John D'Errico le 14 Nov 2020
You use min, because you want MATLAB to take the SMALLER of x+2 and 20. Ergo, min.
Jens Petit-jean
Jens Petit-jean le 14 Nov 2020
ah thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by