MATLAB: I have a function file, I want to input an array and evaluate each cell in that array. How to alter the function file to do this

arrays and function filesduplicate post requiring merging

function x=isoddm(a)
if isnan(a)==1
x=-1;
elseif mod(a,2)==0.5
x=-1;
elseif mod(a,2)==1.5
x=-1;
elseif mod(a,2)==0
x=0;
elseif mod(a,2)==1
x=1;
else
x=nan;
end
The purpose of this function is to see whether an array element is an integer or not and if it is, is it an even or odd number. The problem I am having is that it cannot evaluate each cell in an array individually.

Best Answer

I have found a long and painful answer to my own question that does not involve WR's suggestion. I remade x into x1, x2, and x3. Here is the nested if loop for x1, which determines if a(1) is a real number then proceeds to determine if it is nan or not, then an integer, then even or odd;
function [x1,x2,x3]=isoddm3(a)
% For x1
if isreal(a(1))==0
x1=-1;
elseif isreal(a(1))==1
if isnan(a(1))==1
x1=-1;
elseif mod(a(1),2)==0.5cle
x1=-1;
elseif mod(a(1),2)==1.5
x1=-1;
elseif mod(a(1),2)==0
x1=0;
elseif mod(a(1),2)==1
x1=1;
end
end
It goes on to calculate x2 and x3, which are exactly the same steps for x1 but replaced with x2 or x3. At the end I had to produce a psuedo-array for x using fprintf; fprintf('x=[%g\n %g\n\n %g\n\n\n] Ignore ans',x1,x2,x3) because the answer (ans) would only display x1.
Related Question