time | Calls | line |
---|
| | 1 | function [vars,varData,sortMode,varargin] = ...
|
| | 2 | sortrowsFlagChecks(doIssortedrows,a,vars,sortMode,varargin)
|
| | 3 | % FOR INTERNAL USE ONLY -- This feature is intentionally undocumented.
|
| | 4 | % Its behavior may change, or it may be removed in a future release.
|
| | 5 | %
|
| | 6 |
|
| | 7 | % Parse optional input arguments in tabular sortrows and issortedrows.
|
| | 8 |
|
| | 9 | % Copyright 2016-2019 The MathWorks, Inc.
|
| | 10 |
|
| | 11 | % Parse the VARS
|
< 0.001 | 3 | 12 | sortSigns = [];
|
< 0.001 | 3 | 13 | if nargin < 3 % default is sort by all data vars, do not treat [] as "default behavior"
|
| | 14 | vars = 1:a.varDim.length;
|
| | 15 | varData = a.data;
|
< 0.001 | 3 | 16 | else
|
< 0.001 | 3 | 17 | if isnumeric(vars)
|
< 0.001 | 3 | 18 | sortSigns = sign(vars);
|
< 0.001 | 3 | 19 | vars = abs(vars);
|
| | 20 | % These still need to be validated
|
< 0.001 | 3 | 21 | end
|
< 0.001 | 3 | 22 | try
|
| | 23 | % The reserved name 'RowLabels' is a compatibility special case only for tables.
|
< 0.001 | 3 | 24 | if isequal(convertStringsToChars(vars),'RowNames') && isa(a,'table')
|
| | 25 | vars = 0;
|
| 3 | 26 | else
|
0.015 | 3 | 27 | vars = a.getVarOrRowLabelIndices(vars,true); % allow empty row labels
|
< 0.001 | 3 | 28 | end
|
0.002 | 3 | 29 | varData = a.getVarOrRowLabelData(vars,msgidHelper(doIssortedrows,'EmptyRowNames'));
|
| | 30 | catch ME
|
| | 31 | % Non-numeric var subscripts are converted to valid numeric indices, so an
|
| | 32 | % error here is from a numeric index that was bad to begin with. sortrows
|
| | 33 | % needs a specific error because negative indices are actually valid.
|
| | 34 | ME = matlab.internal.datatypes.throwInstead(ME, ...
|
| | 35 | "MATLAB:badsubscript", ...
|
| | 36 | message(msgidHelper(doIssortedrows,'BadNumericVarIndices')));
|
| | 37 | throwAsCaller(ME);
|
< 0.001 | 3 | 38 | end
|
< 0.001 | 3 | 39 | end
|
| | 40 |
|
| | 41 | % Parse the DIRECTION / MODE
|
< 0.001 | 3 | 42 | if nargin < 4
|
| | 43 | % SORTROWS(T/TT,VARS)
|
< 0.001 | 1 | 44 | sortMode = [];
|
< 0.001 | 2 | 45 | else
|
< 0.001 | 2 | 46 | if rem(numel(varargin),2) == 0
|
| | 47 | % SORTROWS(T/TT,VARS,DIRECTION)
|
| | 48 | % SORTROWS(T/TT,VARS,DIRECTION,N1,V1,N2,V2,...)
|
< 0.001 | 2 | 49 | if isempty(sortMode) && ...
|
| | 50 | (matlab.internal.datatypes.isText(sortMode) || isa(sortMode,'double'))
|
| | 51 | % Empty direction allowed because of legacy sortrows behavior
|
< 0.001 | 2 | 52 | else
|
< 0.001 | 2 | 53 | if ischar(sortMode) || isstring(sortMode)
|
| | 54 | sortMode = cellstr(sortMode);
|
< 0.001 | 2 | 55 | elseif ~iscellstr(sortMode)
|
| | 56 | error(message(msgidHelper(doIssortedrows,'UnrecognizedMode')));
|
< 0.001 | 2 | 57 | end
|
< 0.001 | 2 | 58 | sortModeCell = sortMode;
|
< 0.001 | 2 | 59 | sortMode = zeros(numel(sortMode),1);
|
< 0.001 | 2 | 60 | for ii = 1:numel(sortMode)
|
< 0.001 | 4 | 61 | charFlag = sortModeCell{ii};
|
< 0.001 | 4 | 62 | if isrow(charFlag)
|
< 0.001 | 4 | 63 | if strncmpi(charFlag,'ascend',numel(charFlag))
|
< 0.001 | 2 | 64 | sortMode(ii) = 1;
|
< 0.001 | 2 | 65 | elseif strncmpi(charFlag,'descend',numel(charFlag))
|
< 0.001 | 2 | 66 | sortMode(ii) = 2;
|
< 0.001 | 4 | 67 | end
|
< 0.001 | 4 | 68 | if doIssortedrows % additional issorted directions
|
| | 69 | if strncmpi(charFlag,'monotonic',numel(charFlag))
|
| | 70 | sortMode(ii) = 3;
|
| | 71 | elseif strncmpi(charFlag,'strictascend',max(7,numel(charFlag)))
|
| | 72 | sortMode(ii) = 4;
|
| | 73 | elseif strncmpi(charFlag,'strictdescend',max(7,numel(charFlag)))
|
| | 74 | sortMode(ii) = 5;
|
| | 75 | elseif strncmpi(charFlag,'strictmonotonic',max(7,numel(charFlag)))
|
| | 76 | sortMode(ii) = 6;
|
| | 77 | end
|
< 0.001 | 4 | 78 | end
|
< 0.001 | 4 | 79 | end
|
< 0.001 | 4 | 80 | end
|
< 0.001 | 2 | 81 | if ~all(sortMode)
|
| | 82 | error(message(msgidHelper(doIssortedrows,'UnrecognizedMode')));
|
< 0.001 | 2 | 83 | elseif isscalar(sortMode)
|
| | 84 | sortMode = repmat(sortMode,size(vars));
|
< 0.001 | 2 | 85 | elseif length(sortMode) ~= length(vars)
|
| | 86 | error(message(msgidHelper(doIssortedrows,'WrongLengthMode')));
|
| 2 | 87 | end
|
< 0.001 | 2 | 88 | end
|
| | 89 | else
|
| | 90 | % SORTROWS(T/TT,VARS,N1,V1,N2,V2,...)
|
| | 91 | varargin = [sortMode varargin];
|
| | 92 | sortMode = [];
|
| 2 | 93 | end
|
< 0.001 | 3 | 94 | end
|
| | 95 |
|
< 0.001 | 3 | 96 | if isempty(sortMode)
|
| | 97 | % SORTROWS(T/TT,VARS,N1,V1,...)
|
| | 98 | % SORTROWS(T/TT,VARS,[],N1,V1,...)
|
< 0.001 | 1 | 99 | if isempty(sortSigns)
|
| | 100 | sortMode = ones(size(vars));
|
| 1 | 101 | else
|
< 0.001 | 1 | 102 | sortMode = 1 + (sortSigns == -1); % 1 or 2
|
| 1 | 103 | end
|
< 0.001 | 3 | 104 | end
|
Other subfunctions in this file are not included in this listing.