This is a static copy of a profile report

Home

makeUniqueStrings (Calls: 49, Time: 0.029 s)
Generated 04-Jun-2021 04:11:14 using performance time.
function in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\lang\+matlab\+lang\makeUniqueStrings.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
FastVarOpts>FastVarOpts.get.Namesclass method20
...rtOptionsSpreadsheet.getOptsFromSheetclass method2
ReadTable>ReadTable.buildTableFromDataclass method2
metaDim>metaDim.checkAgainstVarLabelsclass method14
ReadTable>ReadTable.executeclass method2
...t;varNamesDim.validateAndAssignLabelsclass method2
readSpreadsheetfunction1
table.table>table.tableclass method6
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
131
makeUnique(inStr, exclStrOrEle...
310.008 s29.0%
87
exclStrOrElemToChk = validateE...
320.004 s14.1%
113
makeUnique(stringsToCheck, str...
20.002 s6.8%
54
if matlab.internal.datatypes.i...
490.002 s6.1%
126
[inStr, truncated] = truncateS...
240.002 s5.3%
All other lines  0.011 s38.7%
Totals  0.029 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
makeUniqueStrings>makeUniquesubfunction330.008 s27.0%
...Strings>validateExclStrOrElemToChksubfunction320.003 s10.8%
makeUniqueStrings>truncateStringsubfunction260.001 s4.8%
isCharStringfunction490.001 s3.4%
...queStrings>validateMaxStringLengthsubfunction260.000 s1.4%
Self time (built-ins, overhead, etc.)  0.015 s52.5%
Totals  0.029 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function150
Non-code lines (comments, blank lines)72
Code lines (lines that can run)78
Code lines that did run61
Code lines that did not run17
Coverage (did run/can run)78.21 %
Function listing
time 
Calls 
 line
   1 
function [uniqueStrings, modified] = makeUniqueStrings(inStr, excludes, maxStringLength)
   2 
%MATLAB.LANG.MAKEUNIQUESTRINGS Constructs unique strings from input strings
   3 
%   U = MATLAB.LANG.MAKEUNIQUESTRINGS(S) constructs unique elements,
   4 
%   U, from S by appending an underscore and a number to duplicates. S
   5 
%   is a character vector (i.e. a 1xN character array or ''), a cell array
   6 
%   of character vectors, or a string array.
   7 
%
   8 
%   U = MATLAB.LANG.MAKEUNIQUESTRINGS(S, EXCLUDED) makes the elements
   9 
%   in S unique among themselves and unique with respect to EXCLUDED.
  10 
%   MAKEUNIQUESTRINGS does not check EXCLUDED for uniqueness.
  11 
%
  12 
%   U = MATLAB.LANG.MAKEUNIQUESTRINGS(S, WHICHSTRINGS) makes the elements
  13 
%   in S(WHICHSTRINGS) unique among themselves and with respect to the
  14 
%   remaining elements. WHICHSTRINGS is a logical vector or a vector of
  15 
%   indices. MAKEUNIQUESTRINGS does not check the remaining elements for
  16 
%   uniqueness, and returns them unmodified in U. Use this syntax when you
  17 
%   have a cell or string array and need to check that only some elements
  18 
%   of the array are unique.
  19 
%
  20 
%   U = MATLAB.LANG.MAKEUNIQUESTRINGS(S, ___, MAXSTRINGLENGTH)
  21 
%   specifies the maximum strlength, MAXSTRINGLENGTH, of the elements in U.
  22 
%   If MAKEUNIQUESTRINGS cannot make elements in S unique without exceeding
  23 
%   MAXSTRINGLENGTH, it throws an error.
  24 
%
  25 
%   [U, MODIFIED] = MATLAB.LANG.MAKEUNIQUESTRINGS(S, ___) also returns a
  26 
%   logical array the same size as S to denote modified elements.
  27 
%
  28 
%   Examples
  29 
%   --------
  30 
%   Make unique character vectors with respect to workspace variable names
  31 
%
  32 
%       var3 = 0;
  33 
%       varNames = MATLAB.LANG.MAKEUNIQUESTRINGS({'var' 'var2' 'var' 'var3'}, who)
  34 
%
  35 
%   returns the cell array {'var' 'var2' 'var_1' 'var3_1'}
  36 
%
  37 
%   Make unique character vectors by checking only some elements of the array
  38 
%
  39 
%       names = {'Peter' 'Jeremy' 'Campion' 'Nick' 'Nick'};
  40 
%       names = MATLAB.LANG.MAKEUNIQUESTRINGS(names, [2 4])
  41 
%
  42 
%   returns the cell array {'Peter' 'Jeremy' 'Campion' 'Nick_1' 'Nick'}
  43 
%
  44 
%   See also MATLAB.LANG.MAKEVALIDNAME, NAMELENGTHMAX, WHO.
  45 

  46 
%   Copyright 2013-2019 The MathWorks, Inc.
  47 

  48 
% Validate number of inputs.
< 0.001 
     49 
  49
narginchk(1,3); 
  50 

  51 
% Validate input string.
< 0.001 
     49 
  52
inputIsChar = false; 
< 0.001 
     49 
  53
inputIsCell = false; 
  0.002 
     49 
  54
if matlab.internal.datatypes.isCharString(inStr) 
  55 
    inputIsChar = true;
  0.001 
     49 
  56
elseif matlab.internal.datatypes.isCharStrings(inStr, true) 
< 0.001 
     49 
  57
    inputIsCell = true; 
  58 
elseif ~isstring(inStr)
  59 
    error(message('MATLAB:makeUniqueStrings:InvalidInputStrings'))
  60 
elseif any(ismissing(inStr(:)))
  61 
    error(message('MATLAB:makeUniqueStrings:MissingNames', ...
  62 
                  getString(message('MATLAB:string:MissingDisplayText'))));
< 0.001 
     49 
  63
end 
  64 

< 0.001 
     49 
  65
if isempty(inStr) 
< 0.001 
     16 
  66
    uniqueStrings = inStr; 
< 0.001 
     16 
  67
    if inputIsChar 
  68 
        modified = false;
< 0.001 
     16 
  69
    else 
< 0.001 
     16 
  70
        modified = false(size(inStr)); 
< 0.001 
     16 
  71
    end 
< 0.001 
     16 
  72
    return; 
< 0.001 
     33 
  73
end 
< 0.001 
     33 
  74
inStr = string(inStr); 
  75 

  76 
% Set/validate EXCLSTRORELEMTOCHK and MAXSTRINGLENGTH.
< 0.001 
     33 
  77
[~, maxArraySize] = computer; 
< 0.001 
     33 
  78
if nargin < 3 
< 0.001 
      7 
  79
    maxStringLength = maxArraySize; 
< 0.001 
     26 
  80
else 
  0.001 
     26 
  81
    maxStringLength = validateMaxStringLength(maxStringLength, maxArraySize); 
< 0.001 
     33 
  82
end 
  83 

< 0.001 
     33 
  84
if nargin < 2 
< 0.001 
      1 
  85
    exclStrOrElemToChk = string({}); 
< 0.001 
     32 
  86
else 
  0.004 
     32 
  87
    exclStrOrElemToChk = validateExclStrOrElemToChk(excludes, inStr); 
< 0.001 
     33 
  88
end 
  89 

  90 
% Process differently for 2nd option as checkElements or stringsToProtect.
< 0.001 
     33 
  91
if isnumeric(exclStrOrElemToChk) || islogical(exclStrOrElemToChk) % checkElements 
  92 
    
  93 
    % Construct stringsToCheck from STRINGS that need to be made unique.
< 0.001 
      2 
  94
    stringsToCheck = inStr(exclStrOrElemToChk); 
  95 
    
  96 
    % Truncate only the stringsToCheck.
< 0.001 
      2 
  97
    if nargout > 1 
  98 
        truncated = false(size(inStr));
< 0.001 
      2 
  99
    end 
< 0.001 
      2 
 100
    if maxStringLength < maxArraySize 
< 0.001 
      2 
 101
        [stringsToCheck, truncated(exclStrOrElemToChk)] = truncateString(stringsToCheck, maxStringLength); 
< 0.001 
      2 
 102
    end 
 103 
    
 104 
    % Construct stringsToProtect from STRINGS that should not be modified.
< 0.001 
      2 
 105
    if islogical(exclStrOrElemToChk) 
< 0.001 
      2 
 106
        stringsToProtect = inStr(~exclStrOrElemToChk); 
 107 
    else % exclStrOrElemToChk is indices
 108 
        stringsToProtect = inStr(setdiff(1:numel(inStr),exclStrOrElemToChk));
< 0.001 
      2 
 109
    end 
 110 
    
 111 
    % Make stringsToCheck unique against itself and stringsToProtect.
  0.002 
      2 
 112
    [stringsChecked, modifiedInStringsChecked] = ... 
      2 
 113
        makeUnique(stringsToCheck, stringsToProtect, maxStringLength); 
 114 
    
 115 
    % Combine the protected subset of strings with the checked subset.
< 0.001 
      2 
 116
    uniqueStrings = inStr; 
< 0.001 
      2 
 117
    uniqueStrings(exclStrOrElemToChk) = stringsChecked; 
 118 
    
 119 
    % Compute the positions of modified strings in the now completed set.
< 0.001 
      2 
 120
    if nargout > 1 
 121 
        uniquified = false(size(inStr));
 122 
        uniquified(exclStrOrElemToChk) = modifiedInStringsChecked;
< 0.001 
      2 
 123
    end 
< 0.001 
     31 
 124
else % stringsToProtect 
< 0.001 
     31 
 125
    if maxStringLength < maxArraySize 
  0.002 
     24 
 126
        [inStr, truncated] = truncateString(inStr, maxStringLength); 
< 0.001 
      7 
 127
    elseif nargout > 1 
 128 
        truncated = false(size(inStr));
< 0.001 
     31 
 129
    end     
  0.008 
     31 
 130
    [uniqueStrings, uniquified] = ... 
     31 
 131
        makeUnique(inStr, exclStrOrElemToChk, maxStringLength); 
< 0.001 
     33 
 132
end 
 133 

< 0.001 
     33 
 134
if maxStringLength == 0 && inputIsChar 
 135 
    uniqueStrings = char(zeros(1, 0));
 136 
    modified = true;
 137 
    return;
< 0.001 
     33 
 138
end 
 139 

< 0.001 
     33 
 140
if inputIsChar 
 141 
    uniqueStrings = char(uniqueStrings);
< 0.001 
     33 
 142
elseif inputIsCell 
  0.001 
     33 
 143
    uniqueStrings = cellstr(uniqueStrings); 
< 0.001 
     33 
 144
end 
 145 

< 0.001 
     33 
 146
if nargout > 1 
< 0.001 
     14 
 147
    modified = truncated | uniquified; 
< 0.001 
     33 
 148
end 
 149 

< 0.001 
     33 
 150
end 

Other subfunctions in this file are not included in this listing.