function z = HDirProdPs(x,y);
%HorizDirectProdPs    Calculates horizontal direct product of two matrices with equal number of rows.
%                     z(i,:) is the Kronecker product of x(i,:) and y(i,:).
%
%
%
%
%  Usage:    z = HDirProdPs(x,y);
%
%  Input:    x      T x Kx matrix
%            y      T x Ky matrix
%
%  Output:   z      T x (Kx*Ky)
%
%
%
%  Example:   x = [ 1 2;
%                   3 4];
%             y = [5 6 1;
%                  7 8 1];
%
%             the z = HDirProdPs(x,y) gives
%
%             z = [ 5  6  1  10  12  2;
%                  21 24  3  28  32  4];
%
%  Remark: (a)  This could also (but much more slowly) be calculated as
%               z = [];
%               for i=1:Ky;
%                 z = [z,x .* repmat(y(i,:),1,Ky)];
%               end;
%               or
%               for i=1:T;
%                 z(i,:) = kron(x(i,:),y(i,:));
%               end;
%
%           (b) This is the same as x *~ y in Gauss
%
%
%
%
%
% Paul.Soderlind@unisg.ch, Feb 2010
%----------------------------------------------------------------------------*/

[T,Kx] = size(x);         %rows and columns in x
Ky     = size(y,2);       %columns in y

vvx = kron(1:Kx,ones(1,Ky));
vvy = kron(ones(1,Kx),1:Ky);

z = x(:,vvx) .* y(:,vvy);

% z = zeros(T,Kx*Ky);          %an alternative
% z(:,:) = NaN;
% for i=1:Kx;                  %loop over columns in x
%   vv = ((i-1)*Ky+1):(i*Ky);
%   z(:,vv) = repmat(x(:,i),1,Ky).*y;
% end;

% z = zeros(T,Kx*Ky);          %another alternative
% z(:,:) = NaN;
% for i=1:T;                    %loop over rows
%   z(i,:) = kron(x(i,:),y(i,:));
% end;
%----------------------------------------------------------------------------*/
