www.gusucode.com > Matlab动力系统和时间序列分析工具箱 > Matlab动力系统和时间序列分析工具箱/lab432/toolbox/da/da_df_parser.m

    function [coeff_names,funcs]=da_df_parser(df_txt);
% parser of discr. func. string

% format of df_txt only should be:
% c<int. index>*f1(x1,x2,...)+[c<int. index2>*f2(x1,x2,...)]+...
% here f1,f2,...-valid MATLAB expression.
% Example: c12*x1^2/x6+c3*x3+c2*(1/sin(x5))

% last modified 04.02.05

L=length(df_txt);
func_list=df_txt;

coeff_names={};
cn=1;
i=1;
while 1
    switch df_txt(i)
        case 'c'
            j=i+1;
            if j<=L
                if isempty(str2num(df_txt(j)))
                    i=i+1;
                    continue;
                end
            end
            while (j<=L)
                if isempty(str2num(df_txt(j)))
                    j=j-1;
                    break
                end
                j=j+1;
            end
            coeff_names(cn)={df_txt(i:j)};
            func_list(max([1 i-1]):j+1)='_';
            cn=cn+1;
    end
    if i<L
        i=i+1;
    else
        break
    end
end

funcs=cell(size(coeff_names));
i=1;
k=1;
L=length(func_list);
while 1
	if i>L
        break
	end
    switch func_list(i)
        case '_'
            i=i+1;
            continue
        otherwise
            j=i+1;
            while j<=L
                if func_list(j)=='_'
                    j=j-1;
                    break
                else
                    j=j+1;
                end
            end
            str=func_list(i:min([j L]));
            funcs(k)={vectorize(str)};
            k=k+1;
            i=j;
    end
    i=i+1;
end