function tf = issortedrows(A,varargin)
%ISSORTEDROWS   Check if matrix rows are sorted
%   TF = ISSORTEDROWS(A) returns TRUE if the rows of matrix A are sorted in
%   ascending order as a group, namely, returns TRUE if A and SORTROWS(A)
%   are identical. A must be a 2-D matrix of strings.
%
%   TF = ISSORTEDROWS(A,COL) checks if the rows are sorted according to the
%   columns specified by the vector COL.  If an element of COL is positive,
%   SORTROWS checks if the corresponding column in A is sorted in ascending
%   order; if an element of COL is negative, it checks if the corresponding
%   column in A is sorted in descending order. For example,
%   ISSORTEDROWS(A,[2 -3]) first checks if the rows are sorted in ascending
%   order according to column 2; then, checks if rows with equal entries in
%   column 2 are sorted in descending order according to column 3.
%
%   TF = ISSORTEDROWS(A,DIRECTION) and TF = ISSORTEDROWS(A,COL,DIRECTION)
%   check if the rows are sorted according to the specified direction:
%       'ascend'          - (default) Checks if data is in ascending order.
%       'descend'         - Checks if data is in descending order.
%       'monotonic'       - Checks if data is in either ascending or
%                           descending order.
%       'strictascend'    - Checks if data is in ascending order and does
%                           not contain duplicates.
%       'strictdescend'   - Checks if data is in descending order and does
%                           not contain duplicates.
%       'strictmonotonic' - Checks if data is either ascending or
%                           descending, and does not contain duplicates.
%   You can also use a different direction for each column specified by
%   COL, for example, ISSORTEDROWS(A,[2 3],{'ascend' 'descend'}).
%
%   TF = ISSORTEDROWS(A,...,'MissingPlacement',M) also specifies where
%   missing elements (<missing>) should be placed:
%       'auto'  - (default) Missing elements placed last for ascending sort
%                 and first for descending sort.
%       'first' - Missing elements placed first.
%       'last'  - Missing elements placed last.
%
%   See also SORTROWS, ISSORTED, SORT, UNIQUE.

%   Copyright 2016-2019 The MathWorks, Inc.

if ~isstring(A)
    [varargin{:}] = convertStringsToChars(varargin{:});
    tf = issortedrows(A, varargin{:});
else
    [col,dirCodes,missingFlag,scalarExpand] = matlab.internal.math.issortedrowsParseInputs(ismatrix(A),size(A,2),A,varargin{:});
    A = A(:,abs(col));
    if(scalarExpand && ~isempty(dirCodes) && ((dirCodes(1) == 3) || (dirCodes(1) == 6)))
		% If we scalar expanded Monotonic need to check if scalar expand single ascend / descend was true
		dirCodesNew = dirCodes;
        if (dirCodes(1) == 3) 
            dirCodesNew(:) = 1;
        else
            dirCodesNew(:) = 4;
        end
		tf = (matlab.internal.math.issortedrowsFrontToBack(A,dirCodesNew,'MissingPlacement',missingFlag) || matlab.internal.math.issortedrowsFrontToBack(A,dirCodesNew+1,'MissingPlacement',missingFlag));
    else
        % Perform issortedrows check starting with the first specified column and
        % moving on to the next one if ties are present:
        tf = matlab.internal.math.issortedrowsFrontToBack(A,dirCodes,'MissingPlacement',missingFlag);
    end
end
