www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@conbase/rsplot.m

    function hrect = rsplot(con, x, ah, varargin)
%RSPLOT Draw boundary constraints on cross-section plot
%
%   HRECT = RSPLOT(CON, X, AH) draws vertical constraint lines on the
%   cross-section plots in the validation tool.
%
%   CON -- constraint to plot.
%   X   -- cell array of points to make the slice at. Other evaluation
%          points are derived by taking a 51 regular samples between the
%          limits of data on the axes and the model.
%   AH  -- vector of handles to axes with one handle for each input
%          factor.
%
%   HRECT -- handles to the rectangle objects that are created.
%
%   See also CONBASE/CONSTRAINTDISTANCE.

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

if isa( x, 'xregmodel' ),
    warning(message('mbc:conbase:InvalidState6'));
    % The old syntax was 
    %    HRECT = RSPLOT(CON, M, X, AH) 
    % so we need to reassign the inputs
    x = ah;
    ah = varargin{1};
end

if isnumeric( x ),
    x = mat2cell( x(:)', 1, ones( 1, numel( x ) ) );
end

cif = getInputFactors( con );
[LB, UB] = getRange( cif );

for i=1:length(ah)
    xcurrent = x;
    allLines= findobj(ah(i),'Type','line');
    if isempty( allLines ),
        xlim = [LB(i), UB(i)];
    else
        % find xlimits from data
        xdata= get(allLines,'XData');
        xlim= [min([LB(i) xdata{:}]) max([UB(i) xdata{:}])];
    end
    set(ah(i),'XLim',xlim);
    % include point
    xcurrent{i}= sort([x{i},linspace(xlim(1),xlim(2),101)]);
    % find region which is outside boundary
    cvals= constraintDistanceGrid(con,xcurrent)>0;
    pos= find(diff([false;cvals(:);false]));
    ylim= get(ah(i),'YLim');
    ymin= ylim(1);
    height= diff(ylim);
    hrect=gobjects(0);
    k=1;
    allOldChildren = get( ah(i), 'Children' );
    for j= 1:length(pos)-1;
        % loop through the region
        if cvals(pos(j))
            % draw region to show invalid regions
            x1eft = xcurrent{i}(pos(j));
            % add a little bit to the right of the region
            width= xcurrent{i}(pos(j+1)-1)-x1eft + diff(xlim)/101;
            % draw region
            hrect(k)= rectangle('Parent',ah(i),...
                'Position',[x1eft,ymin,width,height],...
                'FaceColor',mbcbdrycolor,...
                'Tag','boundarydisplay',...
                'HitTest','off');
            k=k+1;
        end
    end
    % send rectangles to back so the other lines are visible
    AllChild = get(ah(i),'Children');
    IsRect = ismember(AllChild,hrect);
    set(ah(i),'Children',[AllChild(~IsRect); hrect(:)]);
end
% all boundary rectangles
hrect= findobj(ah,'Tag','boundarydisplay');