What does a(a<0) = 0 mean in matlab?
28 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Abhinav Agrawal
il 23 Giu 2022
Risposto: Cris LaPierre
il 23 Giu 2022
I am new to matlab.
What does a(a<0) = 0 mean?
is it valid if a is an array as well?
0 Commenti
Risposta accettata
Cris LaPierre
il 23 Giu 2022
Yes, it works on arrays. It is using logical indexing to assign values to a. You can learn more about logical indexing in Ch 11 of MATLAB Onramp.
Basically, set any value in a that is less than zero to zero. Here's a simple example.
a = rand(3)
a<0.5
a(a<0.5)=0
0 Commenti
Più risposte (1)
Adam Danz
il 23 Giu 2022
> What does a(a<0) = 0 mean?
a can be a scalar or an array.
This replaces all values in a that are less than 0 with 0.
Example
a = [-6: 2 : 6]
a(a<0) = 0
0 Commenti
Vedere anche
Categorie
Scopri di più su Operating on Diagonal Matrices 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!