In VBA I can do the following:
A = B + IIF(C>0, C, 0)
so that if C>0 I get A=B+C
and C<=0 I get A=B
Is there an operator or function that will let me do these conditionals inline in MATLAB code?
In VBA I can do the following:
A = B + IIF(C>0, C, 0)
so that if C>0 I get A=B+C
and C<=0 I get A=B
Is there an operator or function that will let me do these conditionals inline in MATLAB code?
Inspired by Jonas' answer the function below also works for mixed type input and chars, for which his function isn't stable.
Edit: weeded out the extra conditional options in the cell branch, which were apparently remnants of a previous mistake, this is probably faster, and definitely cleaner.