Borrar filtros
Borrar filtros

making a matrice with conditions

2 visualizaciones (últimos 30 días)
Jens Petit-jean
Jens Petit-jean el 14 de Nov. de 2020
Comentada: Jens Petit-jean el 14 de Nov. de 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

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 14 de Nov. de 2020
Editada: Ameer Hamza el 14 de Nov. de 2020
You can use min()
x = randi([0 19], 1, 20);
y = min(x+2, 20);
  3 comentarios
John D'Errico
John D'Errico el 14 de Nov. de 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 el 14 de Nov. de 2020
ah thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by