making a matrice with conditions
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jens Petit-jean
am 14 Nov. 2020
Kommentiert: Jens Petit-jean
am 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 Kommentare
Akzeptierte Antwort
Ameer Hamza
am 14 Nov. 2020
Bearbeitet: Ameer Hamza
am 14 Nov. 2020
You can use min()
x = randi([0 19], 1, 20);
y = min(x+2, 20);
3 Kommentare
John D'Errico
am 14 Nov. 2020
You use min, because you want MATLAB to take the SMALLER of x+2 and 20. Ergo, min.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!