conditional statement in one line for table columns
Show older comments
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.
Accepted Answer
More Answers (1)
Or, rather than relying on semi-obscure mathematical expressions:
r4 = q2 ./ p2;
r4(p2 > 0) = 2 * r4(p2 > 0);
In my opinion, a lot clearer as to the intent.
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!