www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@modeldev/ShowTestNum.m

    function txt= ShowTestNum(mdev,ax,NoOutliers,X,Y)
%SHOWTESTNUM show test numbers in axes
%
% txt= ShowTestNum(mdev,ax,NoOutliers,X,Y);
% txt= ShowTestNum(mdev,ax);
%   The test numbers will be drawn adjacent to the points in the line with
%   tag 'main line' in ax

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

if nargin==2
    NoOutliers=1;
end

txt=[];

lh=findobj(ax,'Tag','main line');
if isempty(lh)
    % nothing to plot
    return
end

tnvis= get(ax,'Visible');

lh=lh(1);
xdata=get(lh,'XData');
ydata=get(lh,'YData');

if nargin<4
    [X,Y]= getdata(mdev,'fit');
end

% X = {Xglob} the sweepset of sweep means
if iscell(X)
    X1= X{1};
    X=X{end};
else
    X1= X;
end
    
tn= testnum(X);
cols= num2cell(zeros(length(tn),3),2);
if length(xdata )==size(X1,1) && size(X1,3)==length(tn)
    % probably doing one-stage model with sweep data
    ts= tsizes(X1);
    t= cell(length(tn),1);
    for i=1:length(tn)
        % expand test numbers to test sizes
        t{i}= tn(i)*ones(ts(i),1);
    end
    tn= cat(1,t{:});
    % all test number text is black
    cols= num2cell(zeros(length(tn),3),2);
elseif isa(Y,'sweepset') && ~NoOutliers

    tn= testnum(Y);
else
    % find if this is a global model
    p= Parent(mdev);
    while p~=0 && ~isa(p.info,'mdev_local');
        p= p.Parent;
    end
    if p~=0
        % get sweep notes
        [~,cols]= SweepNotes(p.info);
    end
end

if NoOutliers
    % Outlier NaNs already removed from data
    % need to remove from tn anc cols as well
    [~,~,ok]= FitData(mdev);
    tn=tn(ok);
    cols=cols(ok);
end
if length(xdata)==length(tn)


    if mv_zoom(ax(1),'on')
        % clip test numbers if axes is zoomed.
        Clip = 'on';
    else
        Clip = 'off';
    end
    
    txt= gobjects(length(tn),1);
    tstr= mbcnum2str(tn,20,'%-20.12g');
    for i=1:length(xdata)
        % make text objects
        txt(i)=text(xdata(i),ydata(i),tstr(i,:),...
            'Parent',ax(1),...
            'FontSize',8,...
            'Color',cols{i},...
            'HorizontalAlignment','left',...
            'VerticalAlignment','bottom',...
            'Tag','TestNumText',...
            'Visible',tnvis,...
            'Clipping',Clip);
    end
    mbcgui.hgclassesutil.setNotPickable(txt)
    

    % check if we have to show testnumbers for bad data
    lh =findobj(ax,'Tag','BDPts');
    if ~isempty(lh)
        [~,~,tn] = getoutliers(mdev);
        bdx= get(lh,'XData');
        bdy= get(lh,'YData');
        bdok= isfinite(bdy);
        tn= tn(bdok);
        txt = gobjects(1,length(tn));
        tstr= mbcnum2str(tn,20,'%-20.12g');
        for i=1:length(tn)
            txt = text(bdx(i),bdy(i),tstr(i,:),...
                'Parent',ax(1),...
                'FontSize',8,...
                'Color',[0 0 0],...
                'HorizontalAlignment','left',...
                'VerticalAlignment','bottom',...
                'Visible',tnvis,...
                'Tag','TestNumText',...
                'Clipping',Clip);
        end
        mbcgui.hgclassesutil.setNotPickable(txt)
        
    end
else
    warning(message('mbc:modeldev:InvalidState'))
end