This is a static copy of a profile report

Home

validatestring>checkString (Calls: 23, Time: 0.013 s)
Generated 04-Jun-2021 04:11:07 using performance time.
subfunction in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\lang\validatestring.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
validatestringfunction23
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
89
validateattributes(in, {'char'...
230.011 s80.3%
110
if isscalar(out)
230.000 s2.7%
106
out = validStrings(strncmpi(in...
230.000 s2.7%
90
end
230.000 s2.5%
88
if ~(ischar(in) && str...
230.000 s2.0%
All other lines  0.001 s9.7%
Totals  0.013 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
attributesfunction20.010 s76.1%
Self time (built-ins, overhead, etc.)  0.003 s23.9%
Totals  0.013 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function60
Non-code lines (comments, blank lines)14
Code lines (lines that can run)46
Code lines that did run21
Code lines that did not run25
Coverage (did run/can run)45.65 %
Function listing
time 
Calls 
 line
  81 
function out = checkString( in, validStrings, optional_inputs )
  82 

< 0.001 
     23 
  83
    if isstring(validStrings) && any(ismissing(validStrings)) 
  84 
        throwError(optional_inputs, 'missingValueStringList', 'unrecognizedStringChoice');
< 0.001 
     23 
  85
    end 
  86 

< 0.001 
     23 
  87
    try 
< 0.001 
     23 
  88
        if ~(ischar(in) && strcmp(in,'')) 
  0.011 
     23 
  89
            validateattributes(in, {'char', 'string'}, {'scalartext'}); 
< 0.001 
     23 
  90
        end 
  91 
    catch e
  92 
        me = createValidateattributesException(validStrings, optional_inputs,e);
  93 
        throwAsCaller(me);
< 0.001 
     23 
  94
    end 
  95 

  96 
    % do a case insensitive search, but use the case from validStrings,
  97 
    % not the case from the input
  98 
    
< 0.001 
     23 
  99
    if isstring(in) && ismissing(in) 
 100 
        out={};
< 0.001 
     23 
 101
    else 
< 0.001 
     23 
 102
        in_char = char(in); 
< 0.001 
     23 
 103
        if isempty(in_char) 
 104 
            out = validStrings(ismember(validStrings,in_char));
< 0.001 
     23 
 105
        else 
< 0.001 
     23 
 106
            out = validStrings(strncmpi(in_char, validStrings, numel(in_char))); 
< 0.001 
     23 
 107
        end 
< 0.001 
     23 
 108
    end 
 109 

< 0.001 
     23 
 110
    if isscalar(out) 
< 0.001 
     23 
 111
        if iscell(out) 
< 0.001 
     21 
 112
            out = out{1}; 
< 0.001 
     23 
 113
        end 
 114 
    elseif numel(out) > 1
 115 
        % possibly ambiguous match
 116 

 117 
        % determine if all the matching strings are substrings of each other
 118 
        [shortestMatchLength, shortestMatchIdx] = min(cellfun('length', cellstr(out)));
 119 
        
 120 
        shortestMatch = out{shortestMatchIdx};
 121 
        allSubstrings = all(strncmpi(shortestMatch, out, shortestMatchLength));
 122 

 123 
        if allSubstrings
 124 
            % return the shortest match
 125 
            if iscellstr(out)
 126 
                out = shortestMatch;
 127 
            else
 128 
                out = string(shortestMatch);
 129 
            end
 130 
        else
 131 
            throwErrorWithArgDescriptor(in, validStrings, optional_inputs, 'ambiguousStringChoice', 'ambiguousStringChoice');
 132 
        end
 133 
    else
 134 
        if ismissing(in)
 135 
            throwError(optional_inputs, 'missingValueInputString', 'unrecognizedStringChoice');
 136 
        else
 137 
            throwErrorWithArgDescriptor(in, validStrings, optional_inputs, 'unrecognizedStringChoice3', 'unrecognizedStringChoice');
 138 
        end 
< 0.001 
     23 
 139
    end 
< 0.001 
     23 
 140
end 

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