On Fri, May 14, 2010 at 3:19 PM, Stefan Neumann <
address@hidden> wrote:
> is there something like an "inline-if" or "immediate if" in octave?
In Octave 3.3.51+, there is merge() or ifelse()
Jaroslav, thanks for the info. With that I found the answer.
OK, so either go to the test-version or take care of it some other way :-)
% --- file: ifelse.m --- %
function RES = ifelse(c,t,f)
RES = c .* t + (1-c) .* f ;
end
This seems to do it. Testing:
octave:10> a = round(rand(1,10))
a = 0 0 0 1 1 1 1 0 1 0
octave:11> ifelse(a == 1, 2, 3)
ans = 3 3 3 2 2 2 2 3 2 3
... It works for arrays, too, but it doesn't short-circuit (functions can't).
Didn't get that part. Probably something very basic. What did you mean by "doesn't short-circuit" ?
THX
Stefan