I'm trying to define a function as follows:
if nn == 0
tau(nn) = 0
else
tau(nn) = crazy_function(nn)
end
However, I want to do it in a single line. I tried
tau = @(nn) crazy_function(nn).*(nn~=0) + 0.*(nn==0);
But this doesn't work because crazy_function(0)
is not a number (NaN)
. So MATLAB has trouble with the first part of the expression. How can I get MATLAB to simply return 0
when I call tau(0)
by some modification of this line? Thanks!