www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/+cgsimfill/@EvalPoints/surface.m
function hs= surface(V,fh) %SURFACE surface plot of all expressions over evalpoints % % h=surface(V,fh) % Copyright 2005-2014 The MathWorks, Inc. pExpr= V.Expressions; if length(pExpr)~=2 error(message('mbc:cgsimfill:evalpoints:InvalidSize')) end assign(V); vals= V.Values; VarNames=vals{1}; VarValues= vals{2}; % evaluate expressions fValues{1}= i_eval(pExpr(1).info); fValues{2}= i_eval(pExpr(2).info); sz= cellfun('prodofsize',VarValues); N= sum(sz>1); % do a surface if exactly 2 inputs and they are on a grid if V.IsGridData && N==2 && length(fValues{1})==prod(sz) exprNames = pveceval( pExpr, @(i)sprintf('%s(%s)', getname(i), getCageType(i)) ); title = sprintf( '%s, %s', exprNames{1}, exprNames{2} ); ind= find(sz>1); xInd = ind(2); yInd = ind(1); x = VarValues{xInd}; y = VarValues{yInd}; if nargin<2 fh = figure( 'NumberTitle', 'off', 'Visible', 'off' ); end ah = axes( 'Parent', fh ); origNextPlot = get(ah,'NextPlot'); cmaps= {@parula,@cool}; for i=1:length(fValues) crange= [min(fValues{i}(:)) max(fValues{i}(:))]; if crange(1)==crange(2) crange= [crange(1)-1 crange(2)]; end z = reshape(fValues{i},sz(ind)); cdata = mbczdata2cdata(z, cmaps{i}(64), crange); hs{i} = surf(x, y, z, cdata,... 'Parent',ah,... 'FaceColor','Interp',... 'EdgeColor','None',... 'FaceAlpha',1 ); set(ah,'NextPlot','add') end set( ah,'NextPlot', origNextPlot,... 'XLim', mbcmakelimits(x, 'loose'),... 'YLim', mbcmakelimits(y, 'loose') ); mbcxlabel(ah,VarNames{xInd},'Interpreter','none'); mbcylabel(ah,VarNames{yInd},'Interpreter','none'); mbczlabel(ah,title,'Interpreter','none'); mbctitle(ah,title,'Interpreter','none') else error(message('mbc:cgsimfill:evalpoints:InvalidSize2')) end if nargin<2 set( fh, 'Name', title, 'Visible', 'on' ); halfSS = get( 0, 'ScreenSize' )/2; xregcenterfigure( fh, halfSS(3:4) ); end figure(fh);