function mustBeVector(A,allowEmpty)
%MUSTBEVECTOR Validate that value is a 1-by-n or n-by-1 vector
%   MUSTBEVECTOR(A) throws an error if A is not a vector.
%   MATLAB calls isvector to determine if A is a vector.
%
%   MUSTBEVECTOR(A,'allow-all-empties') throws an error if A is neither a
%   vector nor any empty array.
%
%   Class support:
%   All MATLAB classes
%
%   See also: ISVECTOR.
        
%   Copyright 2020 The MathWorks, Inc.

    emptyOK = false;
    if nargin == 2
        % {} and string.empty are empty but not trivial text
        if matlab.internal.datatypes.isScalarText(allowEmpty,false) && startsWith("allow-all-empties",allowEmpty,"IgnoreCase",true)
            emptyOK = true;
        else
            error(message('MATLAB:validatorUsage:invalidSecondInput','mustBeVector','allow-all-empties'));
        end
    end
    
    if isvector(A) || (emptyOK && isempty(A))
        return;
    end
    
    throwAsCaller(MException(message('MATLAB:validators:mustBeVector')));
end
