function [factors, nvArgs] = parseFactorsAndNVArgs(otherArgs)
% PARSEFACTORSANDNVARGS - Parse the names of factors and other NV args for
% anova object methods
%   [FACTORS, NVARGS] = PARSEFACTORSANDNVARGS(OTHERARGS) takes in a cell of
%   arguments, OTHERARGS, which can contain any of the following (in order):
%       - Names of factors
%       - NV args
%   This function will split OTHERARGS into FACTORS, the names of the
%   factors given, and NVARGS, any NVARGS. Both FACTORS and NVARGS may be
%   empty.
%   This function is meant to be used with anova object methods that
%   require specification of factor names.

%   Copyright 2022 The MathWorks, Inc.
if isempty(otherArgs)
    % method(obj)
    factors = [];
    nvArgs = {};
else
    if mod(numel(otherArgs), 2) == 0
        % Even args - assume to be matching NV pairs
        factors = [];
        nvArgs = otherArgs;
    else
        % Odd args - assume factors given along with NV pairs
        factors = otherArgs{1};
        nvArgs = otherArgs(2:end);
    end
end
end