function out = deleteSlices(out, indices, dim)
% DELTESLICES  Delete slices of an N-D array
% out(:, :, ..., indices, :, :, ...) = []; where indices is the dim'th argument.

%   Copyright 2021 The MathWorks, Inc.

inputIsCodist = cellfun(@iscodistributed, {indices, out});
if any(inputIsCodist)
    inputIndex = find(inputIsCodist, 1);
    switch inputIndex
        case 1
            codistributed.pVerifyUsing1d('deleteSlices', indices);
        case 2
            codistributed.pVerifyUsing1d('deleteSlices', out);
    end
end
subsArg = repmat({':'}, 1, max(dim,ndims(out)));
subsArg(dim) = {indices};
subs = substruct('()', subsArg);
% Deleting subsasgn.
if iscodistributed(out)
    out = subsdeleteParens(out, subs);
else % call in-memory deleting subasgn
    out = subsasgn(out, subs, []);
end
end