How to replace values in a matrix?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Molly Baltins
le 21 Sep 2015
Commenté : Star Strider
le 22 Sep 2015
Hello,
I am fairly new to MATLAB and I have a question. How do you replace a value in a matrix? So if I have a matrix A, where A=3,2,5,-6. How can I find, and replace all of the negative numbers with 0? So I want to end up with a matrix of 3,2,5,0.
Thank you!
Molly
0 commentaires
Réponse acceptée
Star Strider
le 21 Sep 2015
One way is to use ‘logical indexing’:
A = [3,2,5,-6];
A(A<0) = 0
A =
3 2 5 0
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Text Analytics Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!