www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xregarx/specialPlots.m

    function out = specialPlots( m, name, axh, x, y , DataOK)
%XREGARX/SPECIALPLOTS  Diagnostic plots particular to dynamic ARX modelling
%   SPECIALPLOTS(M,NAME,AXH,X,Y) returns a handle to the plotted line object.
%
%   NAME can be 'Time Series', 'Time Series Residuals', 'Normal Plot'.

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


switch name,
case 'Time Series',
    out = i_TimeSeries( m, axh, x, y, DataOK, 'PredictedObserved' );
case 'Time Series Residuals',
    out = i_TimeSeries( m, axh, x, y, DataOK, 'Residuals' );
otherwise,
    yy = double( y );
    if m.DynamicOrder(end),
        % code y data
        yy = code( m.StaticModel, yy, nfactors( m.StaticModel ) );
    end
    xx = expanddata( double( x ), yy, m.DynamicOrder, m.Delay );
    out = specialPlots( m.StaticModel, name, axh, xx, yy, DataOK );
    % 20 March 2002: xx and yy are ignored by SpecialPlots. 
    % - If name == 'Predicted/Obsevred' then SpecialPlots get data staright 
    %   from the model browser. 
    % - If name == 'Normal Plot' then no xx, yy data is required at all.
end
return

%------------------------------------------------------------------------------|
function out = i_TimeSeries( m, axh, x, y, DataOK, action )

y0 = get( get( m, 'StaticModel' ), 'InitialConditions' );
delmat = get( m, 'OrderAndDelay' );
md = max( sum( delmat, 1 ) ) - 1;
if length( y0 ) ~= md,
    y0 = double( y(1:md) );
end

x = double( x );
y = double( y );

% Remove duff data
x = x(DataOK,:);
y = y(DataOK,:);

% make predictions
yhat = EvalModel( m, x, y0 );

% time vector
t = ( 0:length( yhat )-1 )' / m.Frequency;
set( get( axh, 'XLabel' ), 'String', 'Time (s)' );

% Plot 
switch action,
    case 'PredictedObserved',
        % Plot measured response
        h1 = line( 'Parent', axh, ...
            'XData', t, ...
            'YData', y, ...
            'Color', 'k', ...
            'Tag', 'main line' );
        xregGui.setLegendData(h1, 'Data');

        % Plot predicted response
        hL = line( 'Parent', axh, ...
            'XData', t, ...
            'YData', yhat, ...
            'Marker', 'None', ...
            'Color', 'b', ...
            'LineStyle', '-' );
        xregGui.setLegendData(hL, 'Predicted=Observed');

        % Set y axis label
        set( get( axh, 'YLabel' ), 'String', ResponseLabel( m ) );
        
    case 'Residuals',
        % Plot residuals
        h1 = line( 'Parent', axh, ...
            'XData', t, ...
            'YData', y - yhat, ...
            'Color', 'b' );
        xregGui.setLegendData(h1, 'Data');
        
        % Set y axis label
        set( get( axh, 'YLabel' ), 'String', 'Residuals');
end

out = h1;