making a matrice with conditions
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Jens Petit-jean
il 14 Nov 2020
Commentato: Jens Petit-jean
il 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
0 Commenti
Risposta accettata
Ameer Hamza
il 14 Nov 2020
Modificato: Ameer Hamza
il 14 Nov 2020
You can use min()
x = randi([0 19], 1, 20);
y = min(x+2, 20);
3 Commenti
John D'Errico
il 14 Nov 2020
You use min, because you want MATLAB to take the SMALLER of x+2 and 20. Ergo, min.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!