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

    function figh=previewcand(des,dims,maxpoints,varargin)
% PREVIEWCAND   Create an object to preview the candidate space
%
% H=PREVIEWCAND(D,NDIMS,MAXPOINTS) opens a figure window and creates
% an object for viewing the candidate points using NDIMS dimensions.
% MAXPOINTS is the maximum number of points that should be plotted;
% if there are mode candidate points than this then the set is sub-
% sampled using an appropriate prime step.  The handle to the preview
% figure is returned.

%  Copyright 2000-2014 The MathWorks, Inc. and Ford Global Technologies, Inc.



if nargin>3
    %update mechanism
    if strcmp(varargin{1},'update')
        figh=varargin{2};
        obj=get(figh,'UserData');
        i_updategraph(obj,des,dims,maxpoints);
        return
    end
end


switch dims
case 1
   func='mvgraph1d';
   ttl='1D Projection of Candidate Set';
case 2
   func='mvgraph2d';
   ttl='2D Projection of Candidate Set';
case 3
   func='mvgraph3d';
   ttl='3D Projection of Candidate Set';
case 4
   func='mvgraph4d';
   ttl='4D Projection of Candidate Set';
end

% create new figure
figh=xregfigure('Name',ttl,...
   'Visible','off',...
   'Renderer','zbuffer');
if ~isempty(varargin)
   set(figh,varargin{:});
end
pnl = mbcgui.container.layoutpanel('Parent', figh, ...
    'BorderType', 'beveledin');
obj=feval(func,pnl,'frame','off','factorselection','exclusive');
set(pnl, 'LayoutComponent', {obj});
i_updategraph(obj,des,dims,maxpoints);

figh.LayoutManager=pnl;
figh.UserData=obj;
set(figh,'Visible','on');
return



function i_updategraph(obj,des,~,maxpoints)

% get data for object
nc = ncand(des);
if nc>maxpoints
    % Need to subsample.
    R = randperm(nc);
    cand = indexcand(des, R(1:maxpoints));
else
    cand = indexcand(des,1:nc);
end

cand=invcode(model(des),cand);

%get limits
lims = limits(des.candset);
lims = invcode(model(des),lims')';
lims = num2cell(lims,2)';

set(obj,'factors',get(model(des),'symbol'),...
    'limits',lims,...
    'data',cand);