www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregcubic/char.m

    function c=char(m,hg,DispOrder)
%CHAR Character representation of xregcubic for display
%
%  c=char(m) creates a multi-line output string for the model m.

%  Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc.

if nargin<2
    hg = 1;
end
if nargin<3
    DispOrder = true;
end

coeffs = double(m);

% Remove zero coefficients from dispay
TermsIn = Terms(m) & coeffs~=0;
if ~any(TermsIn)
    c = '0';
    return
end
if DispOrder
    TermsIn = TermsIn(termorder(m));
    coeffs = coeffs(termorder(m));
end
lab = labels(m,hg,1);

c = [cellstr(num2str(abs(coeffs(TermsIn))))  lab(TermsIn)]';

% Make initial character Sum (c(p)*lab(p) )
c = sprintf(' %s*%s +',c{:});
c = c(1:end-2);

% Remove Constant Term display
c = strrep(c,'*1','');

% remove excess spaces
c = strrep(c,' ','');
c = strrep(c,'+',' + ');
c = strrep(c,'e + ','e+');

% Deal with coefficient signs
tc = find(TermsIn);
if coeffs(tc(1))<0
    % first term different
    c = ['-' c];
end
if length(tc)>1
    f = strfind(c,'+');
    c(f(coeffs(tc(2:end))<0)) = '-';
end

% split c into 80 character lines
cout = mbcutils.splitEquation(c,80);

c = char(cout);