www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@xregdesign/generate.m

    function [d,ok] = generate(d,action)
%GENERATE generate design points for design
%
% [d,ok] = generate(d,action)

%  Copyright 2007-2011 The MathWorks, Inc.

if nargin<2
    action = 'replace';
end

% turn off waitbars
ws = waitbars(d);
d = waitbars(d,false);
ok = true;
[tp,cs] = DesignType(d);
switch tp
    case 1
        % optimise
        d = generateOptimal(d,action);
    case {2,3}
        % get points and transfer to design object
        cs = generate(cs);
        pts=fullset(cs);
        if ~isempty(d.constraints)
            c=reset(d.constraints);
            %Old form:>> [c,in]=eval(c,pts);
            [c, in] = isInside( c, invcode( model( d ), pts ) );
            pts=pts(in,:);
        end
        switch action
            case 'replace'
                [d,ok]=reinit(d,pts,'defined');
                d.style.base=tp;
                d.style.baseinfo=cs;
            case 'add'
                d=augment(d,pts,'points');
                ok=rankcheck(d);
            case 'replacefree'
                d=deletefreepoints(d);
                d=augment(d,pts,'points');
                ok=rankcheck(d);
        end
    otherwise
        error(message('mbc:doe:InvalidDesignType'))
end
d = waitbars(d,ws);

        


function d = generateOptimal(d,action)

Xc = factorsettings(d);
c = constraints(d);
if ~isempty(c)
    Xc = invcode( model(d), Xc );
    [c, OK] = isInside( c, Xc );
else
    OK = true;
end
if ~all(OK)
    d = safechange(d,@(d)delete(d,'indexed',find(~OK)));
    np = size(Xc,1)-sum(OK);
    d = InitializeDesign(d,np,'add');
    warning(message('mbc:doe:InvalidDesign5'))
end

if ~rankcheck(d)
    error(message('mbc:doe:InvalidDesign6'))
end
if npoints(d) || strcmp(action,'add') 
    d = optimise(d);
else
    switch action
        case 'replace'
            d=clear(d);
        case 'replacefree'
            d=deletefreepoints(d);
    end
end