Your replies made me understand why it didn't work. However, in attempting to overcome this problem, I still don't grasp why the following happens:
clc;
clear all;
f1=@(x) x.*(1./x);
g(0,f1) %ok, got the desired result
y=linspace(0,1,10);
g(y(1),f1) %good
g(y,f1) %didn't work: first element is NaN
function out=g(x,f1)
fval=f1(x);
if isnan(fval)==1;
out = 1;
else
out=fval;
end
end
From this, I can see that I can construct the function "element-wise". But how to do it for the whole vector?