This is a static copy of a profile report

Home

validatestring>checkString (Calls: 20, Time: 0.002 s)
Generated 16-Jul-2020 17:09:41 using performance time.
subfunction in file /Applications/MATLAB_R2020a.app/toolbox/matlab/lang/validatestring.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
validatestringfunction20
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
106
out = validStrings(strncmpi(in...
200.000 s17.1%
88
if ~(ischar(in) && str...
200.000 s15.1%
90
end
200.000 s15.1%
112
out = out{1};
200.000 s13.5%
89
validateattributes(in, {'char'...
200.000 s9.9%
All other lines  0.001 s29.3%
Totals  0.002 s100% 
Children (called functions)
No children
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 
     20 
  83
    if isstring(validStrings) && any(ismissing(validStrings)) 
  84 
        throwError(optional_inputs, 'missingValueStringList', 'unrecognizedStringChoice');
< 0.001 
     20 
  85
    end 
  86 

< 0.001 
     20 
  87
    try 
< 0.001 
     20 
  88
        if ~(ischar(in) && strcmp(in,'')) 
< 0.001 
     20 
  89
            validateattributes(in, {'char', 'string'}, {'scalartext'}); 
< 0.001 
     20 
  90
        end 
  91 
    catch e
  92 
        me = createValidateattributesException(validStrings, optional_inputs,e);
  93 
        throwAsCaller(me);
< 0.001 
     20 
  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 
     20 
  99
    if isstring(in) && ismissing(in) 
 100 
        out={};
< 0.001 
     20 
 101
    else 
< 0.001 
     20 
 102
        in_char = char(in); 
< 0.001 
     20 
 103
        if isempty(in_char) 
 104 
            out = validStrings(ismember(validStrings,in_char));
< 0.001 
     20 
 105
        else 
< 0.001 
     20 
 106
            out = validStrings(strncmpi(in_char, validStrings, numel(in_char))); 
< 0.001 
     20 
 107
        end 
< 0.001 
     20 
 108
    end 
 109 

< 0.001 
     20 
 110
    if isscalar(out) 
< 0.001 
     20 
 111
        if iscell(out) 
< 0.001 
     20 
 112
            out = out{1}; 
< 0.001 
     20 
 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 
     20 
 139
    end 
< 0.001 
     20 
 140
end 

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