conditional statement in one line for table columns
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Priyanka Gaikwad
le 23 Juin 2017
Modifié(e) : Guillaume
le 23 Juin 2017
logic: if(p2>0) r4=q2/p2 else r4=2*q2/p2 Question : how to convert this into r4={if p2>0?r4=q2/p2:r4=2*q2/p2} in matlab? p2 and q2 are columns of table.
0 commentaires
Réponse acceptée
alice
le 23 Juin 2017
Have a look at the documentation, for example these: find-array-elements-that-meet-a-condition and element-wise-multiplication.
In your case, you can do:
r4 = (p2>0).*(q2./p2) + (p2<=0).*(q2./p2)*2;
0 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!