Code covered by the BSD License  

Highlights from
Extended (n,k)-gray code

from Extended (n,k)-gray code by Guangdi Li
We extend normal gray code to conside about different range for each digit.

GrayNumberConvertion(Value,Base,Digits )
function [ BaseN,Gray ] = GrayNumberConvertion(Value,Base,Digits )

BaseN = zeros( 1,Digits+1 );
Gray  = zeros( 1,Digits+1 );

for i=1:Digits
    BaseN(i) =  mod(( Value / Base^(i-1)),Base );
    Value = Value - BaseN(i);
end

Shift = 0;
for i = (Digits+1):(-1):1
    Gray( i ) = mod( ( BaseN( i ) - Shift ),Base);
    Shift = Shift + Gray(i);
end

end

Contact us at files@mathworks.com