function [V,INFO] = vectorizeData(Dsys,INFO)
% Vectorizes varying data for interpolation purposes.
% V is of size [GridSize N] where N is the number of variables
% to interpolate.

%   Copyright 2023 The MathWorks, Inc.
nsys = numel(Dsys);
SGS = size(Dsys);  % grid size
nv = [INFO.A.nv INFO.B.nv INFO.C.nv INFO.D.nv INFO.E.nv ...
   INFO.dx.nv INFO.x.nv INFO.u.nv INFO.y.nv ...
   INFO.uDelay.nv INFO.yDelay.nv INFO.xDelay.nv];
V = zeros(nsys,sum(nv));
for ct=1:nsys
   j = 0;
   INFO.A.jv = 0;
   if nv(1)>0
      V(ct,j+1:j+nv(1)) = Dsys(ct).a(INFO.A.iv);  j = j+nv(1);
   end
   INFO.B.jv = j;
   if nv(2)>0
      V(ct,j+1:j+nv(2)) = Dsys(ct).b(INFO.B.iv);  j = j+nv(2);
   end
   INFO.C.jv = j;
   if nv(3)>0
      V(ct,j+1:j+nv(3)) = Dsys(ct).c(INFO.C.iv);  j = j+nv(3);
   end
   INFO.D.jv = j;
   if nv(4)>0
      V(ct,j+1:j+nv(4)) = Dsys(ct).d(INFO.D.iv);  j = j+nv(4);
   end
   INFO.E.jv = j;
   if nv(5)>0
      V(ct,j+1:j+nv(5)) = Dsys(ct).e(INFO.E.iv);  j = j+nv(5);
   end
   % Offsets
   INFO.dx.jv = j;
   if nv(6)>0
      V(ct,j+1:j+nv(6)) = Dsys(ct).dx0(INFO.dx.iv);  j = j+nv(6);
   end
   INFO.x.jv = j;
   if nv(7)>0
      V(ct,j+1:j+nv(7)) = Dsys(ct).x0(INFO.x.iv);  j = j+nv(7);
   end
   INFO.u.jv = j;
   if nv(8)>0
      V(ct,j+1:j+nv(8)) = Dsys(ct).u0(INFO.u.iv);  j = j+nv(8);
   end
   INFO.y.jv = j;
   if nv(9)>0
      V(ct,j+1:j+nv(9)) = Dsys(ct).y0(INFO.y.iv);  j = j+nv(9);
   end
   % Delays
   Delay = Dsys(ct).Delay;
   INFO.uDelay.jv = j;
   if nv(10)>0
      V(ct,j+1:j+nv(10)) = Delay.Input(INFO.uDelay.iv);  j = j+nv(10);
   end
   INFO.yDelay.jv = j;
   if nv(11)>0
      V(ct,j+1:j+nv(11)) = Delay.Output(INFO.yDelay.iv);  j = j+nv(11);
   end
   INFO.xDelay.jv = j;
   if nv(12)>0
      V(ct,j+1:j+nv(12)) = Delay.Internal(INFO.xDelay.iv);
   end
end
V = reshape(V,[SGS(:,SGS>1) size(V,2)]);
