ternary operator in matlab

后端 未结 9 1803
后悔当初
后悔当初 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:44

    If you only need true or false, you can do what MatlabSorter suggests. In case you want a real tertiary operator (i.e. a = b ? c : d), there is none in MATLAB. However, using the file supplied here, you can get close.

提交回复
热议问题