This is a static copy of a profile report

Home

parseArgs (Calls: 3, Time: 0.002 s)
Generated 04-Jun-2021 04:11:26 using performance time.
function in file C:\Program Files\MATLAB\R2020b\toolbox\matlab\datatypes\shared\matlab_datatypes\+matlab\+internal\+datatypes\parseArgs.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
...ategorical>categorical.categoricalclass method3
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
61
[varargin{ischars}] = convertC...
30.000 s13.5%
92
supplied.(pnames{kk}) = setfla...
60.000 s13.3%
94
varargout{nparams+1} = supplie...
30.000 s12.6%
43
setflag = false(1,nparams);
30.000 s12.2%
93
end
60.000 s8.4%
All other lines  0.001 s39.9%
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 function98
Non-code lines (comments, blank lines)51
Code lines (lines that can run)47
Code lines that did run21
Code lines that did not run26
Coverage (did run/can run)44.68 %
Function listing
time 
Calls 
 line
   1 
function [varargout]=parseArgs(pnames,dflts,varargin)
   2 
%PARSEARGS Process parameter name/value pairs for table methods/functions
   3 
%   [A,B,...] = parseArgs(PNAMES,DFLTS,'NAME1',VAL1,'NAME2',VAL2,...)
   4 
%   In typical use there are N output values, where PNAMES is a cell array
   5 
%   of N valid parameter names, and DFLTS is a cell array of N default
   6 
%   values for these parameters. The remaining arguments are parameter
   7 
%   name/value pairs that were passed into the caller. The N outputs
   8 
%   [A,B,...] are assigned in the same order as the names in PNAMES.
   9 
%   Outputs corresponding to entries in PNAMES that are not specified
  10 
%   in the name/value pairs are set to the corresponding value from DFLTS. 
  11 
%   Unrecognized name/value pairs are an error.
  12 
%
  13 
%   [A,B,...,SETFLAG] = parseArgs(...), where SETFLAG is the N+1 output
  14 
%   argument, also returns a structure with a field for each parameter
  15 
%   name. The value of the field indicates whether that parameter was
  16 
%   specified in the name/value pairs (true) or taken from the defaults
  17 
%   (false).
  18 
%
  19 
%   [A,B,...,SETFLAG,EXTRA] = parseArgs(...), where EXTRA is the N+2 output
  20 
%   argument, accepts parameter names that are not listed in PNAMES. These
  21 
%   are returned in the output EXTRA as a cell array.
  22 
%
  23 
%   Example:
  24 
%       pnames = {'color' 'linestyle', 'linewidth'}
  25 
%       dflts  = {    'r'         '_'          '1'}
  26 
%       varargin = {'linew' 2 'linestyle' ':'}
  27 
%       [c,ls,lw] = matlab.internal.datatypes.parseArgs(pnames,dflts,varargin{:})
  28 
%       % On return, c='r', ls=':', lw=2
  29 
%
  30 
%       [c,ls,lw,sf] = matlab.internal.datatypes.parseArgs(pnames,dflts,varargin{:})
  31 
%       % On return, sf = [false true true]
  32 
%
  33 
%       varargin = {'linew' 2 'linestyle' ':' 'special' 99}
  34 
%       [c,ls,lw,sf,ex] = matlab.internal.datatypes.parseArgs(pnames,dflts,varargin{:})
  35 
%       % On return, ex = {'special' 99}
  36 

  37 
%   Copyright 2012-2019 The MathWorks, Inc.
  38 

  39 

  40 
% Initialize some variables
< 0.001 
      3 
  41
nparams = length(pnames); 
< 0.001 
      3 
  42
varargout = dflts; 
< 0.001 
      3 
  43
setflag = false(1,nparams); 
< 0.001 
      3 
  44
unrecog = {}; 
< 0.001 
      3 
  45
nargs = length(varargin); 
  46 

< 0.001 
      3 
  47
SuppliedRequested = nargout > nparams; 
< 0.001 
      3 
  48
UnrecognizedRequested = nargout > (nparams+1); 
  49 

  50 
% Must have name/value pairs
< 0.001 
      3 
  51
if mod(nargs,2)~=0 
  52 
    m = message('MATLAB:table:parseArgs:WrongNumberArgs');
  53 
    throwAsCaller(MException(m.Identifier, '%s', getString(m)));
< 0.001 
      3 
  54
end 
< 0.001 
      3 
  55
ischars = false(1,nargs); 
< 0.001 
      3 
  56
for i = 1:2:nargs 
  57 
    % {'foo'} is not allowed. We just want to find only scalar text - char
  58 
    % vectors and scalar strings.
  59 
    ischars(i) = ischar(varargin{i});
  60 
end
< 0.001 
      3 
  61
[varargin{ischars}] = convertCharsToStrings(varargin{ischars}); 
  62 
% Process name/value pairs
< 0.001 
      3 
  63
for j=1:2:nargs 
  64 
    pname = varargin{j};
  65 
    if ~(isstring(pname) && isscalar(pname) && strlength(pname) > 0)
  66 
        throwAsCaller(MException(message('MATLAB:table:parseArgs:IllegalParamName')));
  67 
    end
  68 
    
  69 
    mask = startsWith(pnames,pname,'IgnoreCase',true); % look for partial match
  70 
    if ~any(mask)
  71 
        if UnrecognizedRequested
  72 
            % If they've asked to get back unrecognized names/values, add this
  73 
            % one to the list.
  74 
            unrecog((end+1):(end+2)) = {char(varargin{j}) varargin{j+1}};
  75 
            continue
  76 
        else % otherwise, it's an error
  77 
            throwAsCaller(MException(message('MATLAB:table:parseArgs:BadParamName',pname)));
  78 
        end
  79 
    elseif sum(mask) > 1
  80 
        mask = matches(pnames,pname,"IgnoreCase",true); % use exact match to resolve ambiguity
  81 
        if sum(mask) ~= 1
  82 
            throwAsCaller(MException(message('MATLAB:table:parseArgs:AmbiguousParamName',pname)));
  83 
        end
  84 
    end
  85 
    varargout{mask} = varargin{j+1};
  86 
    setflag(mask) = true;
  87 
end
  88 

  89 
% Return extra stuff if requested
< 0.001 
      3 
  90
if SuppliedRequested 
< 0.001 
      3 
  91
    for kk = 1:numel(pnames) 
< 0.001 
      6 
  92
        supplied.(pnames{kk}) = setflag(kk); 
< 0.001 
      6 
  93
    end 
< 0.001 
      3 
  94
    varargout{nparams+1} = supplied; 
< 0.001 
      3 
  95
    if UnrecognizedRequested 
  96 
        varargout{nparams+2} = unrecog;
< 0.001 
      3 
  97
    end 
< 0.001 
      3 
  98
end 

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