hammcode.m

来自「Electronic Communication Systems的Matlab源」· M 代码 · 共 32 行

M
32
字号
function hammcode(m)
%
% n = No of Hamming bits
% m = block length
% Example function call:
% hamming(21)
%

n = 0;
while 2^n < m+n+1,
    n = n+1;
end

hamm=num2str(n);
%
% 2 different ways of displaying the result will be shown
%
disp ('The number of Hamming bits is:  ');

% Note that ,hamm, is a string and can thus be passed directly
% to the MATLAB disp(..) function

disp(hamm)

%Secondly, using the %s modifier, the string ,hamm, can be displayed as shown below
fprintf('\nThe number of Hamming bits is: %s\n',hamm);

%
% Finally, using the %e modifier, the result can be siplayed as shown below
fprintf('\nThe number of Hamming bits is: %d\n',n);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?