c=@(x,p)char(mod(idivide(x,1000*26^p),26)+65);
s=@(n)[c(n,3),c(n,2),num2str(mod(n,1000),'-%03d-'),c(n,1),c(n,0)]
说明:
第一行定义一个函数,该函数将产生一个char(从Ato Z)的2个输入函数。索引号x将转换为车牌号,以及一个整数p,该整数将用作26的指数(即26^p)。第二个输入允许将第一个字母数字标牌数字(p=3)的计算向下调整到最后一个(p=0)。
例如,对于第二个数字,每1000 * 26 * 26次迭代循环一次,该操作:mod(idivide(x,1000*26^2),26)返回0到25之间的索引,然后char通过加65将其转换为ASCII (因为索引0基于)
第二行只是将字符连接在一起。每个字母数字字符都使用函数c(x,p)来计算,数字字符只需使用modulo并转换为字符串。
组成车牌号的字符串的每个组成部分如下:
digit #     |    how often is it cycled             |  code
----------------------------------------------------------------
digit 1     | cycle every 1000*26*26*26=1000*26^3   | c(n,3) 
digit 2     | cycle every 1000*26*26   =1000*26^2   | c(n,2) 
digit 3,4,5 | cycle every iteration                 | num2str(mod(n,1000),'-%03d-')
digit 6     | cycle every 1000*26      =1000*26^1   | c(n,1) 
digit 7     | cycle every 1000         =1000*26^0   | c(n,0) 
由于我不能让您在线尝试MATLAB(编辑:实际上您可以在线尝试),因此我将让MATLAB用户可以验证测试用例:
% chose some test cases
n = uint32([0;1;999;1000;675999;676000;456975999]) ;
% work out their plate numbers
plates = s(n) ;
% display results
fprintf('\n%10s | Plate # \n','Index')
for k=1:numel(n)
    fprintf('%10d : %s\n',n(k),plates(k,:))
end
输出:
     Index | Plate # 
         0 : AA-000-AA
         1 : AA-001-AA
       999 : AA-999-AA
      1000 : AA-000-AB
    675999 : AA-999-ZZ
    676000 : AB-000-AA
 456975999 : ZZ-999-ZZ
变体: 
请注意,选项,让sprintf或者fprintf采取数量字符转换的护理是可能的。它允许简化功能c,但在此实现中总体上会导致几个字节(119个字节):
c=@(x,p)mod(idivide(x,1000*26^p),26)+65 ;
s=@(n)sprintf('%c%c-%03d-%c%c\n',[c(n,3),c(n,2),mod(n,1000),c(n,1),c(n,0)]')