function verifyFactorNamesInTable(factorNames, tableVarNames)
%VERIFYVFACTORNAMESINTABLE - Verify that a set of factor names appears in a
%table
%   VERIFYFACTORNAMESINTABLE(FACTORNAMES, TABLEVARNAMES) takes in
%   FACTORNAMES, a set of names of factors, and TABLEVARNAMES, the names of
%   all of the variables in a table. It verifies that all the names in
%   FACTORNAMES appear in TABLEVARNAMES, and verifies that all of
%   FACTORNAMES is unique.

%   Copyright 2022 The MathWorks, Inc.
factorNames = cellstr(factorNames);
if numel(factorNames) ~= numel(unique(factorNames))
    error(message('stats:hypothesis:anova:FactorNamesNotUnique'));
end
missingInd = find(~ismember(factorNames, tableVarNames), 1);
if ~isempty(missingInd)
    error(message('stats:hypothesis:anova:BadVarName', factorNames{missingInd}));
end
end