[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Inline-If ?
From: |
Jaroslav Hajek |
Subject: |
Re: Inline-If ? |
Date: |
Fri, 14 May 2010 15:42:55 +0200 |
On Fri, May 14, 2010 at 3:19 PM, Stefan Neumann <address@hidden> wrote:
>
>
> Hi,
>
> is there something like an "inline-if" or "immediate if" in octave?
>
> in C there is this: RES = (a==1)?1:0
> in some other languages there are functions like if(expr-test , expr_true ,
> expr_false)
>
> THX
> Stefan
>
In Octave 3.3.51+, there is merge() or ifelse() (they're just
aliases). It works for arrays, too, but it doesn't short-circuit
(functions can't).
octave:1> a = 1
a = 1
octave:2> ifelse (a==1, 2, 3)
ans = 2
octave:3> a = round(rand(1,10))
a =
1 0 0 0 1 0 0 0 0 0
octave:4> ifelse(a == 1, 2, 3)
ans =
2 3 3 3 2 3 3 3 3 3
--
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz
- Inline-If ?, Stefan Neumann, 2010/05/14
- Re: Inline-If ?,
Jaroslav Hajek <=