This is a static copy of a profile report

Home

datenum (Calls: 30, Time: 0.041 s)
Generated 16-Jul-2020 17:09:12 using performance time.
function in file /Applications/MATLAB_R2020a.app/toolbox/matlab/timefun/datenum.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
datestrfunction10
imagesci/private/writepngfunction10
datevec>getformatsubfunction10
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
102
n = datenummx(datevec(arg1));
100.026 s65.2%
121
n = dtstr2dtnummx(arg1,matlab....
100.007 s17.0%
77
arg1 = matlab.internal.datatyp...
300.002 s3.8%
175
end
300.001 s1.7%
100
case 1 
300.000 s1.1%
All other lines  0.005 s11.1%
Totals  0.041 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
datevecfunction100.025 s62.3%
cnv2icudffunction100.004 s9.3%
stringToLegacyTextfunction400.000 s0.9%
cellstrfunction100.000 s0.3%
Self time (built-ins, overhead, etc.)  0.011 s27.3%
Totals  0.041 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
Show coverage for parent directory
Total lines in function189
Non-code lines (comments, blank lines)82
Code lines (lines that can run)107
Code lines that did run34
Code lines that did not run73
Coverage (did run/can run)31.78 %
Function listing
time 
Calls 
 line
   1 
function n = datenum(arg1,arg2,arg3,h,min,s)
   2 
%DATENUM Serial date number.
   3 
%	N = DATENUM(V) converts one or more date vectors V into serial date 
   4 
%	numbers N. Input V can be an M-by-6 or M-by-3 matrix containing M full 
   5 
%	or partial date vectors respectively.  DATENUM returns a column vector
   6 
%	of M date numbers.
   7 
%
   8 
%	A date vector contains six elements, specifying year, month, day, hour, 
   9 
%	minute, and second. A partial date vector has three elements, specifying 
  10 
%	year, month, and day.  Each element of V must be a positive double 
  11 
%	precision number.  A serial date number of 1 corresponds to Jan-1-0000.  
  12 
%	The year 0000 is merely a reference point and is not intended to be 
  13 
%	interpreted as a real year.
  14 
%
  15 
%	N = DATENUM(S,F) converts text representing one or more dates to serial
  16 
%	date numbers N using format F. S can be a character array or string
  17 
%	array where each row corresponds to one date, or one dimensional cell
  18 
%	array of strings. DATENUM returns a column vector of M date numbers,
  19 
%	where M is the number of strings in S.
  20 
%
  21 
%	All of the date strings in S must have the same format F, which must be
  22 
%	composed of date format symbols according to Table 2 in DATESTR help.
  23 
%
  24 
%	Certain formats may not contain enough information to compute a date
  25 
%	number.  In those cases, hours, minutes, and seconds default to 0, days
  26 
%	default to 1, months default to January, and years default to the
  27 
%	current year. Date strings with two-character years (e.g. 19-May-88)
  28 
%	are interpreted to be within the 100 years centered around the current
  29 
%	year.
  30 
%
  31 
%	N = DATENUM(S,F,P) or N = DATENUM(S,P,F) uses the specified format F
  32 
%	and the pivot year P to determine the date number N, from S. 
  33 
%   The pivot year is the starting year of the 100-year range in 
  34 
%	which a two-character year resides.  The default pivot year is the 
  35 
%	current year minus 50 years.
  36 
%
  37 
%	N = DATENUM(Y,MO,D) and N = DATENUM([Y,MO,D]) return the serial date
  38 
%	numbers for corresponding elements of the Y,MO,D (year,month,day)
  39 
%	arrays. Y, MO, and D must be arrays of the same size (or any can be a
  40 
%	scalar).
  41 
%
  42 
%	N = DATENUM(Y,MO,D,H,MI,S) and N = DATENUM([Y,MO,D,H,MI,S]) return the
  43 
%	serial date numbers for corresponding elements of the Y,MO,D,H,MI,S
  44 
%	(year,month,day,hour,minute,second) arrays.  The six arguments must be
  45 
%	arrays of the same size (or any can be a scalar).
  46 
%
  47 
%   N = DATENUM(V) converts date represented as date vector (as defined by
  48 
%   DATEVEC) V into a serial date number.
  49 
%
  50 
%	N = DATENUM(S) converts date represented as text S into a serial date
  51 
%	number. S must be in one of the date formats 0,1,2,6,13,14,15,16,23 as
  52 
%	defined by DATESTR. This calling syntax is provided for backward
  53 
%	compatibility, and is significantly slower than the syntax which
  54 
%	specifies the format. If the format is known, the N =
  55 
%	DATENUM(S,F) syntax should be used.
  56 
%
  57 
%	N = DATENUM(S,P) converts date represented as text S, using pivot year
  58 
%	P. If the format is known, the N = DATENUM(S,F,P) or N = DATENUM(S,P,F)
  59 
%	syntax should be used.
  60 
%
  61 
%	Note:  The vectorized calling syntax can offer significant performance
  62 
%	improvement for large arrays.
  63 
%
  64 
%	Examples:
  65 
%		n = datenum('19-May-2000') returns n = 730625. 
  66 
%		n = datenum(2001,12,19) returns n = 731204. 
  67 
%		n = datenum(2001,12,19,18,0,0) returns n = 731204.75. 
  68 
%		n = datenum('19.05.2000','dd.mm.yyyy') returns n = 730625.
  69 
%
  70 
%	See also NOW, DATESTR, DATEVEC, DATETICK.
  71 

  72 
%   Copyright 1984-2019 The MathWorks, Inc.
  73 

< 0.001 
     30 
  74
narginchk(1, 6); 
  75 

  76 
% Shallow adoption of string
  0.002 
     30 
  77
arg1 = matlab.internal.datatypes.stringToLegacyText(arg1); 
  78 

  79 
% parse input arguments
< 0.001 
     30 
  80
isdatestr = ~isnumeric(arg1); 
< 0.001 
     30 
  81
isdateformat = false; 
< 0.001 
     30 
  82
if nargin == 2 
< 0.001 
     10 
  83
    arg2 = matlab.internal.datatypes.stringToLegacyText(arg2); 
< 0.001 
     10 
  84
    isdateformat = ischar(arg2); 
< 0.001 
     20 
  85
elseif nargin == 3 
  86 
    arg2 = matlab.internal.datatypes.stringToLegacyText(arg2);
  87 
    arg3 = matlab.internal.datatypes.stringToLegacyText(arg3);
  88 
    isdateformat = [ischar(arg2), ischar(arg3)];
< 0.001 
     30 
  89
end 
  90 

< 0.001 
     30 
  91
if isdatestr && isempty(arg1) 
  92 
    n = zeros(0,1);
  93 
	warning(message('MATLAB:datenum:EmptyDate'));
  94 
    return;
< 0.001 
     30 
  95
end 
  96 

  97 
% try to convert date character vector or date vector to a date number
< 0.001 
     30 
  98
try 
< 0.001 
     30 
  99
    switch nargin 
< 0.001 
     30 
 100
        case 1  
< 0.001 
     20 
 101
            if isdatestr 
  0.026 
     10 
 102
                n = datenummx(datevec(arg1)); 
< 0.001 
     10 
 103
            elseif ((size(arg1,2)==3) || (size(arg1,2)==6)) && ... 
     10 
 104
                    any(abs(arg1(:,1) - 2000) < 10000) 
< 0.001 
     10 
 105
                n = datenummx(arg1); 
 106 
            else
 107 
                n = arg1;
< 0.001 
     20 
 108
            end 
< 0.001 
     10 
 109
        case 2 
< 0.001 
     10 
 110
            if isdateformat 
< 0.001 
     10 
 111
                if ischar(arg1) 
< 0.001 
     10 
 112
					arg1 = cellstr(arg1); 
< 0.001 
     10 
 113
                end 
< 0.001 
     10 
 114
                if ~iscellstr(arg1) 
 115 
                    %At this point we should have a cell array.  Otherwise error.
 116 
                    error(message('MATLAB:datenum:NotAStringArray'));
< 0.001 
     10 
 117
                end 
< 0.001 
     10 
 118
                if isempty(arg2) 
 119 
                    n = datenummx(datevec(arg1));
< 0.001 
     10 
 120
                else 
  0.007 
     10 
 121
                    n = dtstr2dtnummx(arg1,matlab.internal.datetime.cnv2icudf(arg2));              
< 0.001 
     10 
 122
                end 
 123 
            else
 124 
                n = datenummx(datevec(arg1,arg2));
< 0.001 
     10 
 125
            end 
 126 
        case 3
 127 
			if any(isdateformat)
 128 
				if isdateformat(1) 
 129 
					format = arg2;
 130 
					pivot = arg3;
 131 
				elseif isdateformat(2)
 132 
					format = arg3;
 133 
					pivot = arg2;
 134 
				end
 135 
				if ischar(arg1)
 136 
					arg1 = cellstr(arg1);
 137 
				end
 138 
                if ~iscellstr(arg1)
 139 
                    %At this point we should have a cell array.  Otherwise error.
 140 
                    error(message('MATLAB:datenum:NotAStringArray'));
 141 
                end
 142 
				icu_dtformat = matlab.internal.datetime.cnv2icudf(format);
 143 
				showyr =  strfind(icu_dtformat,'y'); 
 144 
                if ~isempty(showyr)
 145 
                    wrtYr =  numel(showyr);
 146 
                    checkYr = diff(showyr);
 147 
                    if any(checkYr~=1)
 148 
                        error(message('MATLAB:datenum:YearFormat'));
 149 
                    end
 150 
                    switch wrtYr
 151 
                        case 4
 152 
                            icu_dtformat = strrep(icu_dtformat,'yyyy','yy');
 153 
                        case 3
 154 
                            icu_dtformat = strrep(icu_dtformat,'yyy','yy');
 155 
                    end
 156 
                end
 157 
                if (isempty(format))
 158 
                    n = datenummx(datevec(arg1,pivot));
 159 
                else
 160 
                    if (isempty(pivot))
 161 
                        n = dtstr2dtnummx(arg1,icu_dtformat);
 162 
                    else
 163 
                        n = dtstr2dtnummx(arg1,icu_dtformat,pivot);
 164 
                    end
 165 
                end
 166 
            else
 167 
                verifySizes(arg1,arg2,arg3);
 168 
                n = datenummx(arg1,arg2,arg3);
 169 
			end
 170 
        case 6
 171 
            verifySizes(arg1,arg2,arg3,h,min,s);
 172 
            n = datenummx(arg1,arg2,arg3,h,min,s);
 173 
        otherwise
 174 
            error(message('MATLAB:datenum:Nargin'));
< 0.001 
     30 
 175
    end 
 176 
catch exception   
 177 
    if (nargin == 1 && ~isdatestr)
 178 
        identifier = 'MATLAB:datenum:ConvertDateNumber';
 179 
    elseif (nargin == 1 && isdatestr) || (isdatestr && any(isdateformat))
 180 
        identifier = 'MATLAB:datenum:ConvertDateString';
 181 
    elseif (nargin > 1) && ~isdatestr && ~any(isdateformat)
 182 
        identifier = 'MATLAB:datenum:ConvertDateVector';
 183 
    else
 184 
        identifier = exception.identifier;
 185 
    end
 186 
    newExc = MException( identifier,'%s',getString(message('MATLAB:datenum:Failed')));
 187 
    newExc = newExc.addCause(exception);
 188 
    throw(newExc);
< 0.001 
     30 
 189
end 

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