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

    function p = designproperties(c,p,m)
%DESIGNPROPERTIES properties for command-line
%
% p = designproperties(c,p)

%  Copyright 2007 The MathWorks, Inc.

CLSID = mfilename('class');
[p,OK] = PersistentStore(p,CLSID);
if ~OK
    p = iMakeProps(c,p,m);
    PersistentStore(p,CLSID);
end


function p = iMakeProps(c,p,m)

p = designproperties(c.cset_lhs,p,m);

p = addprop(p,'StratifyLevels',...
    @iGetStratifyLevels,...
    @iSetStratifyLevels,...
    'vector int',{[0 Inf],nfactors(c)},...
    'Number of levels for each factors');

p = addprop(p,'StratifyValues',...
    @iGetStratifyValues,...
    @iSetStratifyValues,...
    'cell',[],...
    'Stratify levels');



function v = iGetStratifyLevels(c,m)
v = get(c,'StratifyLevels');
vals = get(c,'exactlevels');
for i=1:length(v)
    if v(i)==-1
        v(i) = length(vals{i});
    end
end

function c = iSetStratifyLevels(c,v,m)

c = set(c,'StratifyLevels',v);

function v = iGetStratifyValues(c,m)

v = get(c,'exactlevels');
lvls = get(c,'StratifyLevels');
lims = limits(c);
for i=1:length(v)
    if lvls(i)>0
        % values are equispaced
        v{i} = linspace(lims(i,1),lims(i,2),lvls(i));
    end
    % values need to be uncoded
    v{i} = invcode(m,v{i}(:),i);
end

function c = iSetStratifyValues(c,v,m)

lvls = get(c,'StratifyLevels');
if numel(v)~=numel(lvls)
   error(message('mbc:doe:InvalidValue35', numel( lvls )))
end
lims = limits(c);
for i=1:length(v)
    limN = invcode(m,lims(i,:)',i);
    if ~isnumeric(v{i}) || any(v{i}>limN(2)) || any(v{i}<limN(1))
        error(message('mbc:doe:InvalidValue36', sprintf( '%g', limN( 1 ) ), sprintf( '%g', limN( 2 ) ), i))
    end
    if lvls(i)>0 && isequal(v{i}(:),linspace(limN(1),limN(2),lvls(i)))
        % use levels if values are equispaced
        v{i}= [];
    elseif ~isempty(v{i})
        % values need to be coded
        v{i} = code(m,v{i}(:),i);
        lvls(i) = -1;
    end

end

c = set(c,'exactlevels',v);
c = set(c,'StratifyLevels',lvls);