MATLAB: I am looking for a code to identify if the entered number is odd or even. For example: “ABC 123”, I would be really grateful if someone shares the code.

MATLABodd even functionstring

I tried using mod function but it doesn't work as my input contains Alphabet and numbers both.

Best Answer

You need to remove the characters before using mod function. You can use regexp to remove all non digits characters.
The following code uses regexp to match digits only in variable t , with the expression '\d' . The indices returned by regexp functions are used to get the digit values, before converting them to a number with num2str.
t = "ABC123";
t = char(t);
num = str2num(t(regexp(t,'\d')));
if(~mod(num,2))
disp('Number is even')
else
disp('Number is odd')
end