from Luhn Algorithm Functions by David Chandler
Luhn algoritm check and computation of missing digit.

luhncheck(num)
function valid = luhncheck(num)
% valid = luhncheck(num). If num is a string of numbers, then valid
% will determine if the given number adheres to the Luhn algorithm.  This
% algorithm is used to verify credit card numbers, amongst other
% identification numbers.
sum = 0;
alt = 0;
temp = 0;
for i = length(num):-1:1
    temp = str2num(num(i));
    if (alt)
        temp = temp * 2;
        if (temp > 9)
            temp = temp - 9;
        end
    end
    sum = sum + temp;
    alt = ~alt;
end
valid = (mod(sum,10) == 0);

Contact us at files@mathworks.com