function D = augstate(D)
% Appends states as outputs.

%   Copyright 1986-2023 The MathWorks, Inc.
a = D.a;
nx = size(a,1);
nfd = length(D.Delay.Internal);
[rs,cs] = size(D.d);
if nfd==0
   % No internal delays
   D.c = [D.c ; eye(nx,'like',a)];
   D.d = [D.d ; zeros(nx,cs,'like',a)];
   D.y0 = [D.y0 ; D.x0];
else
   ny = rs-nfd;
   D.c = [D.c(1:ny,:) ; eye(nx,'like',a) ; D.c(ny+1:rs,:)];
   D.d = [D.d(1:ny,:) ; zeros(nx,cs,'like',a) ; D.d(ny+1:rs,:)];
   D.y0 = [D.y0(1:ny,:) ; D.x0 ; D.y0(ny+1:rs,:)];
end
D.Delay.Output = [D.Delay.Output ; zeros(nx,1)];
D.Scaled = false;
