simple matrix process for some values

1 visualización (últimos 30 días)
Kamyar Mazarei
Kamyar Mazarei el 8 de Abr. de 2021
Respondida: Star Strider el 8 de Abr. de 2021
hi im new to matlab
i want to process some of the matrix values but not all
like if i have a matrix i just want to add 10 to any value thats less than 5
its just an example can you help me with basic commands on this?
thank you

Respuesta aceptada

Star Strider
Star Strider el 8 de Abr. de 2021
Use ‘logical indexing’:
M = randi(10,6)
Mnew = M+(M<5)*10
producing (in this random instance):
M =
8 6 5 2 1 2
9 4 10 6 3 1
2 2 2 3 1 4
2 3 8 2 5 5
4 10 8 3 1 2
1 7 6 9 9 10
Mnew =
8 6 5 12 11 12
9 14 10 6 13 11
12 12 12 13 11 14
12 13 8 12 5 5
14 10 8 13 11 12
11 7 6 9 9 10
See the documentation section on Matrix Indexing for details.

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing 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