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

    function hs= surface(m,x,hAx,options,cmodel,X,Y,PE)
%SURFACE Draw surface plot for model
%
%   hs = SURFACE(M, X, hAX, OPTS, CONMODEL, X, Y, PE)

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

if nargin<3
    hAx=gca;
end
if nargin<4
    options=[0 1 1 0];
end
if length(options)<4
    % clip, light
    options = [options 1 0];
end

pevshade= options(1);
xtrans= options(2);
dispExterior = mbconoff(options(3));
lightvis = mbconoff(options(4));

if nargin<5
    cmodel= [];
end
if nargin<7
    if pevshade
        [PE,X,~,Y]= pevgrid(m,x);
        PE= sqrt(PE);
    else
        [Y,X]= GenTable(m,x);
        PE=Y;
    end
end


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);
PE= squeeze(PE);

% 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';
    PE=PE';
end

lh=findobj(hAx,'Type','light');
CurView= get(hAx,'View');
if all(CurView==[0 90])
    CurView= [-37.5 30];
end

if ~isempty(lh)
    Lprops= set(lh(1));
    Lprops= [fieldnames(Lprops)';get(lh(1),fieldnames(Lprops))];
else
    Lprops=[];
end
set(hAx,'CLimMode','auto','XLimMode','auto','YLimMode','auto','ZLimMode','auto');
if isempty(cmodel)
    hs=surf(X1,X2,Y,PE,...
        'Parent',hAx,...
        'FaceColor','interp','EdgeColor','none',...
        'FaceLighting','gouraud','BackFaceLighting','reverselit');
else
    cvals = squeeze( constraintDistanceGrid( cmodel, x ) );
    if xtrans
        cvals= cvals';
    end
    hs = xregsurfaceb(X1, X2, Y, cvals, PE,...
        'DisplayExterior', dispExterior, ...
        'parent',hAx,...
        'FaceColor','interp','EdgeColor','none',...
        'FaceLighting','gouraud','BackFaceLighting','reverselit');
end
xregGui.setLegendData(hs, 'Model fit');
if isempty(Lprops)
    % make new light
    hL=light('Parent',hAx,'Visible',lightvis,'Color','w','Style','local');
else
    % Use Previous light properties
    hL=light('Parent',hAx,'Visible',lightvis,Lprops{:});
end
set(hAx,'View',CurView)
camlight(hL,'headlight')


set(hAx,'Box','on')

% axes labels
set(get(hAx,'ZLabel'),...
    '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');