If a number in a matrix is <9 add 5 to it
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
James Knight
il 29 Ott 2019
Risposto: Jos (10584)
il 29 Ott 2019
Hi
I was reading on Matlab refrences :
A = 4×4
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1
Replace all values less than 9 with the value 10.
A(A < 9) = 10
If I want to add 5 to the values that are less than 9 rather than repalce them with 10 how would I go about it please?
Thanks
0 Commenti
Risposta accettata
Jos (10584)
il 29 Ott 2019
Use the same selection on the right hand side of the equal sign
A(A<9) = A(A<9) + 5
I myself prefer to code it like this
tf = A < 9
A(tf) = A(tf) + 5
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Operators and Elementary Operations 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!