MATLAB: How to Make a function accept vector inputs

programming

function Ml = myseries(t)
n=0;
while (n<10)
Ml = sum(t.^n/(gamma(n + 1)));
n = n+1;
end
The above code runs well as long as the input variable is a scalar; for vectorized inputs, it fails. What might be wrong?

Best Answer

You did not specify how the output should be , 1x1 or Nx1 , you can try this way :
function Ml = myseries(t)
n=0;
ctr=1;
while (n<10)
Ml(ctr) = sum(t.^n/(gamma(n + 1)));
n = n+1;
ctr=ctr+1;
end