%% Build Predictor Model
% Discretize an identified state-space model to build a one-step ahead predictor of its response.
% Create a continuous-time identified state-space model using estimation data.

load iddata2
sysc = ssest(z2,4);

%
% Predict the 1-step ahead predicted response of sysc.

predict(sysc,z2)

%
% Discretize the model.

sysd = c2d(sysc,0.1,'zoh');

%
% Build a predictor model from the discretized model, sysd.

[A,B,C,D,K] = idssdata(sysd);
Predictor = ss(A-K*C,[K B-K*D],C,[0 D],0.1);

% Predictor is a two-input model which uses the measured output and input signals ([z1.y z1.u]) to compute the 1-step predicted response of sysc.
%
% Simulate the predictor model to get the same response as the predict command.

lsim(Predictor,[z2.y,z2.u])

% The simulation of the predictor model gives the same response as predict(sysc,z2).
% Copyright 2012 The MathWorks, Inc.