function R = getResponse(D)
% GETRESPONSE returns a lftDataM vector with one entry per frequency 
% point containing a static model of the frequency response at each 
% frequency. This is used to support the UFRD.RESPONSEDATA property.
% Note: The response data excludes the delays for consistency with 
% ResponseData in FRD models.

%   Author(s): P. Gahinet
%   Copyright 1986-2011 The MathWorks, Inc.
if ~all(logicalfun(@isstatic,D.Blocks))
   error(message('Control:lftmodel:getResponseData1'))
end

% Fold blocks that are not StaticModel's
hasDynamics = ~logicalfun(@(x) isa(x,'StaticModel'),D.Blocks);
if any(hasDynamics)
   warning(message('Control:lftmodel:getResponseData2'))
   D = foldBlocks(D,hasDynamics);
end

% Construct static model [A B;C D] and extract desired matrix
IC = D.IC;   B = D.Blocks;
nf = numel(IC.Frequency);
R = ltipack.lftdataM.array([nf 1]);
for ct=1:nf
   R(ct).IC = IC.Response(:,:,ct);
   R(ct).Blocks = B;
end
