1) You need to turn your factorial script into a function. However, note that MATLAB has a function called factorial already. So either use MATLAB's function, or name your function something else (e.g., make a file called myfactorial.m and fill in the code).
2) Your while loop is flawed if x is a vector, since the if-test is not doing what you think it is. Put a for-loop around that while loop and loop through all the elements of x. E.g., if this outer loop is for k=1:numel(x), then use x(k) in the while loop instead of just x. E.g.,
x = input(etc)
e = zeros(size(x)); % your result vector, see (3) below
for k=1:numel(x)
n = 0;
while( use x(k) here instead of just x )
etc
3) You are not summing the terms! You compute a term as y, then you throw it away and overwrite it on the next iteration with another term. So start with a result vector, e.g. e = zeros(size(x)), then in your loop have e(k) = e(k) + y;
