function [varargout] = ndgridVectors(V)
% NDGRIDVECTORS vectors for creating a default NDGRID 
%   [xg, yg] = NDGRIDVECTORS(V) creates grid vectors xg = 1:N and yg = 1:M,
%   where size(V) is M-by-N. The grid vectors (xg, yg) can be passed to 
%   NDGRID to give [X,Y] = NDGRID(xg,yg), such that the size of X and Y 
%   equals the size of V.
%
%   [xg, yg, zg] = NDGRIDVECTORS(V) creates grid vectors xg = 1:N, yg = 1:M,
%   and zg = 1:p, where size(V) is M-by-N-by-P. The grid vectors (xg, yg, Zg) 
%   can be passed to NDGRID to give [X,Y,Z] = NDGRID(xg,yg,zg), such that 
%   the size of X and Y and Z equals the size of V.
%
%   The outputs are column vectors, distributed if V is distributed in that
%   dimension.

%   Copyright 2011-2021 The MathWorks, Inc.

sizev = size(V);
varargout = arrayfun(@(x) (1:x)', sizev, 'UniformOutput', false);
if iscodistributed(V)
    codistV = getCodistributor(V);
    distDimV = codistV.Dimension;
    partitionV = codistV.Partition;
    varargout{distDimV} = codistributed(varargout{distDimV},...
        codistributor1d(1, partitionV));
end
end
