function [M,xkeep] = sminreal(M)
%SMINREAL  Eliminates structurally disconnected states, delays, and blocks.
%
%   MS = SMINREAL(M) simplifies the model M by eliminating all model
%   components that are not connected to any input or output.
%
%   In state-space models, SMINREAL eliminates all states and internal
%   delays that are structurally disconnected from the inputs and outputs.
%   The simplified model MS is structurally minimal, that is, minimal when
%   all nonzero entries of SYS.A, SYS.B, SYS.C, and SYS.E are set to 1.
%
%   In generalized models, SMINREAL further eliminates all tunable or
%   uncertain blocks that are structurally disconnected from the inputs
%   and outputs.
%
%   See also MINREAL, SS, SPARSS, MECHSS, GENMAT, GENSS, GENFRD.

%   Copyright 1986-2020 The MathWorks, Inc.
if nargout>1 && nmodels(M)~=1
   error(message('Control:transformation:minreal2','sminreal'))
end
try
   [M,xkeep] = sminreal_(M);
catch E
   ltipack.throw(E,'command','sminreal',class(M))
end
% Note: Do not reduce LFT models to double or LTI when no blocks are left. 
% This makes the output type unpredictable and code that tries to access
% M.Blocks property may fail.