help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: conditional expr operator in Octave?


From: Søren Hauberg
Subject: Re: conditional expr operator in Octave?
Date: Wed, 29 Jul 2009 11:30:00 +0200

ons, 29 07 2009 kl. 11:18 +0200, skrev Jaroslav Hajek:
> is anyone (beside me) interested in supporting the ternary conditional
> operator (?:) from C/C++ in Octave?

Yeah, I've been missing that from time to time. I often end up writing a
function for this behaviour. Something like (off the top of my head)

  function retval = ternary (expr, true_val, false_val)
    if (expr)
      retval = true_val;
    else
      retval = false_val;
    endif
  endfunction

works fine. With this you can just do

  foo = ternary (x > 7, "it's big", "it's small");

Søren



reply via email to

[Prev in Thread] Current Thread [Next in Thread]