www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+twostage/SweepPlots.m
classdef SweepPlots < mbcgui.multiview.View %SweepPlots sweep plots for two-stage models % Copyright 2015-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (SetAccess=private) %NumRows number of rows of plots NumRows=2; %PrintLayout layout for printing PrintLayout %AxHand axes handles for plots AxHand %PlotOptions plot options PlotOptions %CardLyt card layout to hide plots CardLyt %SperPage sweeps per page SperPage = 4; end methods function obj = SweepPlots(varargin) %SweepPlots - constructor obj@mbcgui.multiview.View(varargin{:}); createLayout(obj) addMessageServiceListener(obj, 'NodeUpdated',@obj.onNodeUpdated) end function update(obj) %update update plots ms = obj.MessageService; TS = ms.Model; if ms.Status set(obj.CardLyt,'CurrentCard',1); ax= obj.AxHand; % enabled transform actions obj.Actions.Actions(2).Enabled = HasTransform(TS) || HasTransform(get(TS,'local')); XG= ms.GlobalXData; % Global Input Data % set all axes vis=on since some may have been off in last view % (will do necessary turn vis off below) set(ax,'Visible','on'); % Find out the loop size...depends if we are on last page if ms.CurrentPage== ms.NumPages; % we are on the last page... N=size(XG,3) - (ms.NumPages-1)*obj.SperPage; % do not necessarily want to display all axes AxH=ax(N+1:end); set(findobj(AxH),'Visible','off'); else N=obj.SperPage; end SNos= (ms.CurrentPage-1)*obj.SperPage+1:(ms.CurrentPage-1)*obj.SperPage+N; VarSym= char(get(TS,'symbol')); VarSym = VarSym(nlfactors(TS)+1:end,:); PlotOpts = num2cell(ms.PlotOptions); if PlotOpts{3} PlotOpts{3} = ms.CILevel; end for k=1:N % N=1,2 or 3; Xs= ms.XData(:,:,SNos(k)); Ys= ms.YData(:,:,SNos(k)); % Display Experimental Point (Natural and Code values) % data to display Experimental Point (Natural and Coded values) Xg_nat= XG{SNos(k)}; globVarStr= [VarSym, blanks(size(Xg_nat,2))',... num2str(Xg_nat','%10.4g')]; % plot results (Blue points real data , blue line Local regression fit % Green Line TS fit) cla(ax(k)); set(ax(k),... 'XLimMode','auto','YLimMode','auto',... 'NextPlot','add') set(get(ax(k),'ZLabel'),'UserData',[]); % call twostage/sweep_plot sNumStr = sweep_plot(TS,{Xs,XG(:,:,SNos(k))},Ys,ax(k),PlotOpts); %create info str for tooltip patch numBlankLines = size(globVarStr,1)-2; if numBlankLines<0 % globVarStr is only one line! pad this upto 2 lines globVarStr = char(globVarStr,' '); infoStr = char(sprintf('%10s','s'),sNumStr); elseif numBlankLines==0 % pad statStr upto size of globVarStr infoStr= char(sprintf('%10s','s'),sNumStr); else blnks = repmat(' ',[numBlankLines,1]); infoStr= char(sprintf('%10s','s'),sNumStr,blnks); end infoStr = cat(2,globVarStr, infoStr); set(get(ax(k),'Title'),'String',sprintf('Test %3g',testnum(XG(:,:,SNos(k))))) % whole area for showing info-patch is set(ax(k),'NextPlot','replacechildren',... 'ButtonDownFcn',{@iAxButtonDown, infoStr}); end xlh=get(ax,{'XLabel'}); if ~isempty(xlh) set([xlh{:}]','Visible','off'); end xlh=get(ax(max(1,N-1):N),{'XLabel'}); set([xlh{:}]' ,'Visible','on','FontSize',8); else set(obj.CardLyt,'CurrentCard',2); end end end methods (Access=private) function createLayout(obj) %createLayout create layout of axes %-----------the subplot axes----------------------% MarkerStyles= {'o','x','square','diamond','v','^','>','<','pentagram','hexagram'}; hAx= cell(obj.NumRows*2,1); axPanel = mbcgui.container.layoutpanel('Parent',obj.Parent); for i=1:obj.NumRows*2 hAx{i}=axes('Parent',axPanel,... 'ButtonDownFcn',@(h,evt) mv_zoom(h),... 'Box','on',... 'Units','pixels',... 'XGrid','on','YGrid','on',... 'Position',[0 0 1 1],... 'Tag','subplots',... 'FontSize',8,... 'LineStyleOrder',MarkerStyles,... 'NextPlot','replacechildren'); end % NOTE: plot routines expect Ax handles in row-wise order hence axesGrid = xreggridbaglayout(axPanel,... 'visible','off',... 'dimension', [obj.NumRows, 2],... 'elements',hAx,... 'border', [50 45 20 20], ... 'gapx', 50, ... 'gapy', 55); obj.PrintLayout = axesGrid; set(axPanel,'LayoutComponent',{axesGrid}); % NOTE: plot routines expect Ax handles in row-wise order hence hAx = [hAx{:}]; hAx= reshape(hAx,obj.NumRows,2)'; obj.AxHand = hAx(:)'; obj.CardLyt = xregcardlayout(obj.Parent,'visible','off','numcards',2); attach(obj.CardLyt,axPanel,1); createActions(obj) obj.ContentHandle = obj.CardLyt; end function createActions(obj) %createActions create actions for plot options ms = obj.MessageService; obj.Actions.Actions = [ mbcgui.actions.ToggleAction(@obj.onOptionChanged,... 'Show &Removed Data','Show removed data',[]); mbcgui.actions.ToggleAction(@obj.onOptionChanged,... 'Show &Transformed Units','Show transformed data',[]); mbcgui.actions.ToggleAction(@obj.onOptionChanged,... 'Show &Confidence Levels','Show confidence levels',[]); mbcgui.actions.ToggleAction(@obj.onOptionChanged,... 'Show &Absolute X','Show absolute x',[]); mbcgui.actions.ToggleAction(@obj.onOptionChanged,... 'Show &Model Range','Show absolute x',[])]; set(obj.Actions.Actions,{'Selected'},num2cell(ms.PlotOptions)') uic = uicontextmenu('Parent', ancestor(obj.Parent,'figure')); createMenuItem(obj.Actions,uic); set(obj.AxHand,'UIContextMenu',uic); end function onNodeUpdated(obj,~,~) %onNodeUpdated update views message received update(obj) end function onOptionChanged(obj,~,~) %onOptionChanged plot options changed ms = obj.MessageService; ms.PlotOptions = [obj.Actions.Actions.Selected]; setpref(mbcprefs('mbc'),'LocalPlotOpts',ms.PlotOptions) update(ms); end end end function iAxButtonDown(ax, ~, str) %iAxButtonDown button down event for axes downtype=get(ancestor(ax,'figure') ,'SelectionType'); switch downtype case {'extend','open'} % zoom mv_zoom(ax); case 'normal' % display data patch with info xregDisplayDataPatch(ax, str, [], false) end end