Effacer les filtres
Effacer les filtres

simple matrix process for some values

2 vues (au cours des 30 derniers jours)
Kamyar Mazarei
Kamyar Mazarei le 8 Avr 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

Réponse acceptée

Star Strider
Star Strider le 8 Avr 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.

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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