This is a static copy of a profile report

Home

Function details for str2numThis is a static copy of a profile report

Home

str2num (Calls: 4, Time: 0.001 s)
Generated 19-Jun-2021 04:39:09 using performance time.
function in file /nfs/linux/matlab-2019b/toolbox/matlab/strfun/str2num.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
cnn_train>parse_optionssubfunction4
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
49
[x,ok] = protected_conversion(...
40.001 s44.2%
45
s(s==char(0)) = ' ';
40.000 s15.1%
47
[m,n] = size(s);
40.000 s8.8%
34
if ~ischar(s) || ~ismatrix(s)
40.000 s5.2%
31
s = convertStringsToChars(s);
40.000 s5.2%
All other lines  0.000 s21.4%
Totals  0.001 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
str2num>protected_conversionsubfunction40.000 s29.6%
Self time (built-ins, overhead, etc.)  0.001 s70.4%
Totals  0.001 s100% 
Code Analyzer results
Line numberMessage
48Extra comma is unnecessary in IF statement before newline.
53Extra comma is unnecessary in IF statement before newline.
56Extra comma is unnecessary in ELSEIF statement before newline.
60Extra comma is unnecessary in FOR statement before newline.
62Extra comma is unnecessary in IF statement before newline.
Coverage results
Show coverage for parent directory
Total lines in function76
Non-code lines (comments, blank lines)34
Code lines (lines that can run)42
Code lines that did run14
Code lines that did not run28
Coverage (did run/can run)33.33 %
Function listing
time 
Calls 
 line
   1 
function [x,ok] = str2num(s)
   2 
%STR2NUM Convert character array or string scalar to numeric array
   3 
%   X = STR2NUM(S) converts a character array or string scalar  
   4 
%   representation of a matrix of numbers to a numeric matrix. For example,
   5 
%       
   6 
%        S = ['1 2'         str2num(S) => [1 2;3 4]
   7 
%             '3 4']
   8 
%
   9 
%   The numbers in S should be text representations of a numeric values.  
  10 
%   Each number may contain digits, a decimal point, a leading + or - sign, 
  11 
%   an 'e' or 'd' preceding a power of 10 scale factor, and an 'i' or 'j' for 
  12 
%   a complex unit.
  13 
%
  14 
%   If S does not represent a valid number or matrix, STR2NUM(S) returns 
  15 
%   the empty matrix.  [X,OK]=STR2NUM(S) returns OK=0 if the conversion fails.
  16 
%
  17 
%   CAUTION: STR2NUM uses EVAL to convert the input argument, so side
  18 
%   effects can occur if S contains calls to functions.  Use
  19 
%   STR2DOUBLE to avoid such side effects or when S contains a single
  20 
%   number.
  21 
%
  22 
%   Also spaces can be significant.  For instance, str2num('1+2i') and 
  23 
%   str2num('1 + 2i') produce x = 1+2i while str2num('1 +2i') produces
  24 
%   x = [1 2i].  These problems are also avoided when you use STR2DOUBLE.
  25 
%
  26 
%   See also STR2DOUBLE, NUM2STR, HEX2NUM, CHAR.
  27 

  28 
%   Copyright 1984-2016 The MathWorks, Inc.
  29 

< 0.001 
      4 
  30
if nargin > 0 
< 0.001 
      4 
  31
    s = convertStringsToChars(s); 
< 0.001 
      4 
  32
end 
  33 

< 0.001 
      4 
  34
if ~ischar(s) || ~ismatrix(s) 
  35 
   error(message('MATLAB:str2num:InvalidArgument'))
< 0.001 
      4 
  36
end 
  37 

< 0.001 
      4 
  38
if isempty(s) 
  39 
    x = [];
  40 
    ok=false;
  41 
    return
< 0.001 
      4 
  42
end 
  43 

  44 
% Replace any char(0) characters with spaces
< 0.001 
      4 
  45
s(s==char(0)) = ' '; 
  46 

< 0.001 
      4 
  47
[m,n] = size(s); 
< 0.001 
      4 
  48
if m==1, 
< 0.001 
      4 
  49
  [x,ok] = protected_conversion(['[' s ']']); % Always add brackets 
  50 
else
  51 
    semi = ';';
  52 
    space = ' ';
  53 
    if ~any(any(s == '[' | s == ']')), % String does not contain brackets
  54 
        o = ones(m-1,1);
  55 
        s = [['[';space(o)] s [semi(o) space(o);' ]']]';
  56 
    elseif ~any(any(s(1:m-1,:) == semi)), % No ;'s in non-last rows
  57 
        s = [s,[semi(ones(m-1,1));space]]';
  58 
    else                               % Put ;'s where appropriate
  59 
        spost = space(ones(m,1));
  60 
        for i = 1:m-1,
  61 
            last = find(s(i,:) ~= space,1,'last');
  62 
            if s(i,n-last+1) ~= semi,
  63 
                spost(i) = semi;
  64 
            end
  65 
        end
  66 
        s = [s,spost]';
  67 
    end
  68 
    [x,ok] = protected_conversion(s);
< 0.001 
      4 
  69
end 
< 0.001 
      4 
  70
if isnumeric(x) 
< 0.001 
      4 
  71
    return 
  72 
end
  73 
if ischar(x) || iscell(x) || isstring(x)
  74 
   x = [];
  75 
   ok = false;
  76 
end

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