function [X,sizeX,blockSizeZ] = internal_repmat(X,varargin)
% This function is undocumented and will change in a future release.

%   Copyright 2023 The MathWorks, Inc.

if (nargout > 1)
    sizeX = size(X);
    X = repmat(X,varargin{:});
    blockSizeZ = iRepmatArgsToBlockSizeOfOutput(varargin);
    [sizeX,blockSizeZ] = iUniformizeSizes(sizeX,blockSizeZ);
else
    X = repmat(X,varargin{:});
end
end

function blockSize = iRepmatArgsToBlockSizeOfOutput(args)
% Compute size of output block matrix.
% B = repmat(A,M,N)         -> blockSize = [M,N]
% B = repmat(A,[M,N])       -> blockSize = [M,N]
% B = repmat(A,N)           -> blockSize = [N,N]
% B = repmat(A,P1,...,Pn)   -> blockSize = [P1,...,Pn]
% B = repmat(A,[P1,...,Pn]) -> blockSize = [P1,...,Pn]
numArgs = numel(args);
if (numArgs == 1)
    blockSize = args{1};
    if (numel(blockSize) == 1)
        blockSize = [blockSize,blockSize];
    end
else
    blockSize = [args{:}];
end
end

function [sizeX,sizeZ] = iUniformizeSizes(sizeX,sizeZ)
nX = numel(sizeX);
nZ = numel(sizeZ);
if (nZ > nX)
    sizeX = [sizeX, ones(1,nZ-nX)];
elseif (nX > nZ)
    sizeZ = [sizeZ, ones(1,nX-nZ)];
end
end