www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregmodel/contour.m

    function [c,h]= contour(m,x,hAx,V,options,cmodel)
%CONTOUR contour plot of model
%
% [c,h]= contour(m,x,hAx,V,options,cmodel)
%  m        model
%  x        cell array of input values to specify grid - exactly two inputs must be
%           nonscalar
%  hAx      axes handle
%  V        color 
%  options  [labels,fill,transform]
%  cmodel   boundary model

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

if nargin<3
   hAx=gca;
end
if nargin<4
   V=[];
end
if nargin<5
    options= [0 1 1];
end
if nargin<6
    cmodel= [];
end

labels= options(1);
fill= options(2);
xtrans= options(3);


% generate the data
[Y,X]= GenTable(m,x);
   
xy=find(cellfun('prodofsize',x)>1 );
% squeeze into a 2-d plot
X1= squeeze(X{xy(1)});
X2= squeeze(X{xy(2)});
Y= squeeze(Y);

if ~isempty(cmodel)
    % evaluate boundary model and set values outside boundary to NaN
    cvals= squeeze(constraintDistanceGrid(cmodel,x));
else
    cvals = [];
end

% getting labels for the axes
ylabstr= ResponseLabel(m);
% xlab is a cell array
xlab =InputLabels(m);

if ~xtrans
   xlab(xy(1:2))= xlab(xy([2 1]));
   X1=X2';
   X2=squeeze(X{xy(1)})';
   Y= Y';
   cvals = cvals';
end



Argin={X1,X2,Y};
if ~isempty(V)
   Argin=[Argin {V}];
end

if any(isfinite(Y(:)))
    if fill
        [c,h]=contourf(hAx,Argin{:});
    else
        [c,h]=contour(hAx,Argin{:});
    end
    xregGui.setLegendData(h, 'Model fit');
    % label contours (inline labels)
    if labels && ~isempty(h)
        clabel(c,h);
    end
    
    if ~isempty(cmodel)
        % evaluate boundary model and set values outside boundary to NaN
        set(hAx,'NextPlot','add');
        contour(hAx,X1,X2,cvals,[0 0],...
            'HitTest','off',...
            'Fill','on',...
            'FaceColor',mbcbdrycolor);
    end
else
    % nothing to show in contour
    c=[];
    h=[];
    
    % make sure view is 2d
    view(hAx,2)
end


set(hAx,'Box','on');
% label axes
set(get(hAx,'Title'),...
    'String',ylabstr,'Interpreter','none');
set(get(hAx,'XLabel'),...
    'String',xlab{xy(1)},'Interpreter','none');
set(get(hAx,'YLabel'),...
    'String',xlab{xy(2)},'Interpreter','none');
set(get(hAx,'Title'),...
   'String',ylabstr,'Interpreter','none');