ternary operator in matlab

后端 未结 9 2001
后悔当初
后悔当初 2020-12-08 19:07

is there a way of typing for if like:

var = (cond) ? true : false;

or do we have to use this format?

if (cond)
 true
else
          


        
9条回答
  •  佛祖请我去吃肉
    2020-12-08 19:49

    Replace

    c = (x ? a : b)
    

    by

    c = subsref({b; a}, substruct('{}', {x + 1}))
    

    x should be a boolean value or 1 or 0.
    true or 1 will select a
    false or 0 will select b
    This should work with all what cells can contain and can also be used in an intricate formular!

提交回复
热议问题