www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgsurfview/@dataviewer/plot.m
function plot(obj,data,plottype) %PLOT Plot the supplied data against the specified variables. % % PLOT(data,plottype) % data is an array of up to 4 instances of cgsurfview.svdata % % plottype is the index of the required plot type in the list returned by % dataviewer.getPlotTypes. % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. lpt = length(obj.plottypes); if (nargin<3) error(message('mbc:cgsurfview:dataviewer:InvalidArgument1')); end if plottype<1 || plottype>lpt error(message('mbc:cgsurfview:dataviewer:InvalidArgument2')); end num_plots = numel(data); if (num_plots>obj.MaxPlots) error(message('mbc:cgsurfview:dataviewer:InvalidArgument3')); end for m=1:obj.MaxPlots set(obj.plotframes{m},'Visible','off'); end obj.currentplottype = plottype; ptinputs = length(obj.plottypes(plottype).vars); % p will contain just the frames we want to show. d = obj.framedata; e = obj.haserror; cardtoshow = repmat(plottype,1,num_plots); for i = 1:num_plots pd = data(i); if isError(pd) % print string on "error frame" set(d{end,i},'String',getErrorMessage(pd)); cardtoshow(i) = size(d, 1); e(plottype,i) = -1; % error else numvars = getNumVariables(pd); if numvars<ptinputs % missing inputs. check for "reduced inputs" plot type newpt = plottype; while newpt~=0 && length(obj.plottypes(newpt).vars)>numvars newpt = obj.plottypes(newpt).reducedinputs; end if newpt~=0 cardtoshow(i) = newpt; d = i_do_plot(obj,d,i,newpt,pd); e(plottype,i) = newpt; % no error, but a different plot type else % print string on "error frame" set(d{end,i},'String','Not enough inputs for this plot type'); cardtoshow(i) = size(d, 1); e(plottype,i) = -1; % error end else % plot normally d = i_do_plot(obj,d,i,plottype,pd); e(plottype,i) = false; % no error end end set(obj.plotframes{i},'BarTitle',getTitle(pd)); end obj.framedata = d; obj.haserror = e; obj.visiblecards = cardtoshow; for n = 1:num_plots set(obj.plotcards{n},'currentcard',cardtoshow(n)); end if num_plots==1 set(obj.plotgrid, 'dimension', [1 1], ... 'elements', obj.plotframes(1), ... 'packstatus', 'on'); elseif num_plots==2 set(obj.plotgrid, 'dimension', [1 2], ... 'elements', obj.plotframes(1:2), ... 'packstatus', 'on'); else set(obj.plotgrid, 'dimension', [2 2], ... 'elements', obj.plotframes, ... 'packstatus', 'on'); end vis = get(obj.plotgrid, 'Visible'); for n = 1:num_plots set(obj.plotframes{n}, 'Visible', vis); end if num_plots<obj.MaxPlots for n = num_plots+1:obj.MaxPlots set(obj.plotframes{n}, 'Visible', 'off'); end end set(obj.layout, 'currentcard', 1); %-------------------------- % d is a copy of obj.framedata % i is the position of the plot (between 1 & 4) % pt is the plot type index function d = i_do_plot(obj,d,i,pt,data) plotobj = d{pt,i}; if isempty(plotobj) func = obj.plottypes(pt).createfcn; opts = obj.plottypes(pt).optionsobj; panel = get(obj.plotcards{i},'Parent'); plotobj = feval(func,obj,opts,panel); attach(obj.plotcards{i},plotobj,pt); d{pt,i} = plotobj; end plot(plotobj,data);