function b = lengthenVar(a, n)
%FOR INTERNAL USE ONLY -- This feature is intentionally undocumented.
%   Its behavior may change, or it may be removed in a future release.
%   


%   Copyright 2023 The MathWorks, Inc.

if ~istabular(a)
    error(message('parallel:array:UnsupportedFunction', upper(mfilename), underlyingType(a)));
end

b = a;
if n <= height(a)
    return
end

inCodistr = getCodistributor(a);
if inCodistr.Dimension == 1
    % Each worker has whole rows. Ask the last worker to grow.
    part = inCodistr.Partition;
    rowsToAdd = n - height(a);
    part(end) = part(end) + rowsToAdd;
    outLP = getLocalPart(a);
    if spmdIndex == numel(part)
        outLP = lengthenVar(outLP, part(end));
    end
    % Build the new distribution
    outCodistr = codistributor1d(1, part, [n, width(a)]);
else
    % Different workers have different variables. Ask each to resize.
    outLP = lengthenVar(getLocalPart(a), n);
    % The result has the same partitioning but larger height.
    outCodistr = codistributor1d(2, inCodistr.Partition, [n, width(a)]);
end

b = codistributed.pDoBuildFromLocalPart(outLP, outCodistr);
end
