⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gfpretty.m

📁 经典通信系统仿真书籍《通信系统与 MATLAB (Proakis)》源代码
💻 M
字号:
function gfpretty(a,b,n)
%GFPRETTY Pretty display of a GF(P) polynomial.
%       BFPRETTY(A) prints GF(P) polynomial in a traditional polynomial
%       format. All zero coefficient terms are eliminated.
%
%       BFPRETTY(A, STR) prints GF(P) polynomial with the polynomial variable
%       specified in a string variable STR.
%
%       BFPRETTY(A, STR, N) uses screen width N instead of the default 79.
%
%      The polynomial A is in ascending order, i.e.,
%      A = [a_0, a_1, a_2,..., a_(n-1), a_n] represents
%            A(X) = a_0 + a_1 X + a_2 X^2 +...+ a_(n-1) X^(n-1) + a_n X^n
%      This function can also take polynomial not in GF(P).
%
%      See also GFADD, GFMUL, GFDIV, GFTUPLE

%      Wes Wang 6/8/94, 7/21/94, 10/7/95.
%      Copyright (c) 1995-96 by The MathWorks, Inc.
%      $Revision: 1.1 $  $Date: 1996/04/01 17:59:14 $

%input validation check, it is not necessary for the limitation.
%if ~isempty([find(a~=floor(a)), find(a<0)])
%  error('The polynomial coeficients must be in GF(P)')
%end;

% default values.
if nargin < 2
 b = 'X';
elseif ~isstr(b)
        disp('The second input variable for GFPRETTY should be a string');
      b = 'X';
end;
if nargin < 3
       n = 79;
end;

% initial condition
did = [];
diu = [];
a = gftrunc(a);

% assign string based on the GF polynomial
if length(a) <= 1
    did = num2str(a);
else
    for i=1:length(a)
        if a(i) ~= 0
            % the first one is constant
            if i == 1
                bb = num2str(a(1));
            else
                if abs(a(i)) == 1
                    bb = b;
                else
                    bb = [num2str(abs(a(i))), ' ', b];
                end;
            end;
            % the first assignment without '+'
            if isempty(did)
                did = bb;
                spa = length(bb);
            else
                if a(i) > 0
                    did = [did, ' + ', bb];
                else
                    did = [did, ' - ', bb];
           end;
                spa = length(bb) + 3;
            end;
            % match the power term
            if i > 2
                pow = num2str(i-1);
            else
                pow = '';
            end
            % set the string to be a same length
            diu = [diu, setstr(ones(1,spa)*32), pow];
            did = [did, setstr(ones(1,length(pow))*32)];
        end;
    end;
end;

% printout
if length(did) < n
    % under limit
    spa = floor((n-length(did))/2);
    pow = setstr(ones(1,spa)*32);
    did = [pow, did];
    diu = [pow, diu];
    disp(' ')
    disp(diu)
    disp(did)
else
    %over the limit
    while(length(did) >=n)
        ind = findstr(did, ' + ');
        sub_ind = max(find(ind < 79));
        disp(' ')
        disp(diu(1:max(ind(sub_ind)-1)));
        disp(did(1:max(ind(sub_ind)-1)));
        % add space for indent
        diu = ['          ',diu(ind(sub_ind):length(diu))];
        did = ['          ',did(ind(sub_ind):length(did))];
    end;
    disp(' ')
    disp(diu);
    disp(did);
end;

%--end of GFPRETTY--

⌨️ 快捷键说明

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