www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregcubic/term_order2monomial.m
function terms_out = term_order2monomial( obj, terms_in ) %TERM_ORDER2MONOMIAL Convert the format of polynomial term specification. % % ORDER = MODEL.TERM_ORDER2MONOMIAL( CHARS ) % % 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-2007 The MathWorks, Inc. varlabels = get(obj,'symbol'); numvars = numel(varlabels); if size(terms_in,2) ~= numvars, error('mbc:xregcubic:term_order2monomial:InvalidValue',... 'Input must be a TERM matrix with %d columns',numvars); end if any( terms_in < 0 ), error(message('mbc:xregcubic:term_order2monomial:InvalidValue1')); end N = size( terms_in, 1); terms_out = cell(N,1); for ii=1:N, terms_out{ii} = []; for jj=1:numvars, if terms_in(ii,jj)>0, terms_out{ii} = [terms_out{ii}, repmat(jj,1,terms_in(ii,jj))]; end end end