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

    function terms_out = term_monomial2order( obj, terms_in )
%TERM_MONOMIAL2ORDER Convert the format of polynomial term specification.
%
%   ORDER = MODEL.TERM_MONOMIAL2ORDER( MONOMIALS )
%
%   Polynomial terms can be specified in three ways:
%   * CHAR, for example 'x^2*y^3*z'
%   * ORDER, giving the order (power index) of each variable [2 3 1]
%   * MONOMIAL, a list of variables to multiply [1 1 2 2 2 3]
%
%   Where there are several terms specified, these should be a cell array
%   of chars {'x','x*y^2','z^3'}, a matrix of orders [1 0 0;1 2 0;0 0 3]
%   or a cell array of monomials {[1],[1 2 2],[3 3 3]}. Note the special
%   case of a constant, char = '1', order=[0 0 0], monomial=[].

%   Copyright 2006 The MathWorks, Inc.

numvars = numel(get(obj,'symbols'));

if ~iscell(terms_in),
    terms_in = {terms_in};
end

N = numel(terms_in);
terms_out = zeros(N,numvars);
for ii=1:N,
    for jj=1:numel(terms_in{ii}),
        terms_out(ii,terms_in{ii}(jj)) = terms_out(ii,terms_in{ii}(jj)) + 1;
    end
end