This is a static copy of a profile report

Home

datenum (122 calls, 0.219 sec)
Generated 05-Aug-2011 13:00:27 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/timefun/datenum.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
datestrfunction41
imagesci/private/writepngfunction40
datevec>getformatsubfunction40
sunUpDownfunction1
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
96
n = datenummx(datevec(arg1));
400.120 s55.0%
115
n = dtstr2dtnummx(arg1,cnv2icu...
400.055 s25.0%
92
try
1220.033 s15.0%
93
switch nargin
1220.011 s5.0%
163
case 6, n = datenummx(arg1,arg...
10 s0%
All other lines  0.000 s0.0%
Totals  0.219 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
datevecfunction400.109 s50.0%
timefun/private/dtstr2dtnummxMEX-file400.022 s10.0%
timefun/private/cnv2icudffunction400.022 s10.0%
iscellstrfunction400 s0%
cellstrfunction400 s0%
Self time (built-ins, overhead, etc.)  0.066 s30.0%
Totals  0.219 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
[ Show coverage for parent directory ]
Total lines in function179
Non-code lines (comments, blank lines)79
Code lines (lines that can run)100
Code lines that did run26
Code lines that did not run74
Coverage (did run/can run)26.00 %
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 one or more date strings S to serial date
16 % numbers N using format string F. S can be a character array where each
17 % row corresponds to one date string, or one dimensional cell array of
18 % strings. DATENUM returns a column vector of M date numbers, where M is
19 % 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 % Formats with 'Q' are not accepted by DATENUM.
24 %
25 % Certain formats may not contain enough information to compute a date
26 % number. In those cases, hours, minutes, and seconds default to 0, days
27 % default to 1, months default to January, and years default to the
28 % current year. Date strings with two character years are interpreted to
29 % be within the 100 years centered around the current 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, given the date
33 % string S. 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(S) converts the string or date vector (as defined by
48 % DATEVEC) S into a serial date number. If S is a string, it must be in
49 % one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR.
50 % This calling syntax is provided for backward compatibility, and is
51 % significantly slower than the syntax which specifies the format string.
52 % If the format is known, the N = DATENUM(S,F) syntax should be used.
53 %
54 % N = DATENUM(S,P) converts the date string S, using pivot year P. If the
55 % format is known, the N = DATENUM(S,F,P) or N = DATENUM(S,P,F) syntax
56 % should be used.
57 %
58 % Note: The vectorized calling syntax can offer significant performance
59 % improvement for large arrays.
60 %
61 % Examples:
62 % n = datenum('19-May-2000') returns n = 730625.
63 % n = datenum(2001,12,19) returns n = 731204.
64 % n = datenum(2001,12,19,18,0,0) returns n = 731204.75.
65 % n = datenum('19.05.2000','dd.mm.yyyy') returns n = 730625.
66 %
67 % See also NOW, DATESTR, DATEVEC, DATETICK.
68
69 % Copyright 1984-2009 The MathWorks, Inc.
70 % $Revision: 1.24.4.15 $ $Date: 2010/08/23 23:13:36 $
71
122 72 if (nargin<1) || (nargin>6)
73 error(nargchk(1,6,nargin, 'struct'));
74 end
75
76 % parse input arguments
122 77 isdatestr = ~isnumeric(arg1);
122 78 isdateformat = false;
122 79 if nargin == 2
40 80 isdateformat = ischar(arg2);
82 81 elseif nargin == 3
82 isdateformat = [ischar(arg2), ischar(arg3)];
83 end
84
122 85 if isdatestr && isempty(arg1)
86 n = zeros(0,1);
87 warning(message('MATLAB:datenum:EmptyDate'));
88 return;
89 end
90
91 % try to convert date string or date vector to a date number
0.03 122 92 try
0.01 122 93 switch nargin
122 94 case 1
81 95 if isdatestr
0.12 40 96 n = datenummx(datevec(arg1));
41 97 elseif ((size(arg1,2)==3) || (size(arg1,2)==6)) && ...
98 any(abs(arg1(:,1) - 2000) < 10000)
41 99 n = datenummx(arg1);
100 else
101 n = arg1;
102 end
41 103 case 2
40 104 if isdateformat
40 105 if ischar(arg1)
40 106 arg1 = cellstr(arg1);
40 107 end
40 108 if ~iscellstr(arg1)
109 %At this point we should have a cell array. Otherwise error.
110 error(message('MATLAB:datenum:NotAStringArray'));
111 end
40 112 if isempty(arg2)
113 n = datenummx(datevec(arg1));
40 114 else
0.05 40 115 n = dtstr2dtnummx(arg1,cnv2icudf(arg2));
40 116 end
117 else
118 n = datenummx(datevec(arg1,arg2));
119 end
1 120 case 3
121 if any(isdateformat)
122 if isdateformat(1)
123 format = arg2;
124 pivot = arg3;
125 elseif isdateformat(2)
126 format = arg3;
127 pivot = arg2;
128 end
129 if ischar(arg1)
130 arg1 = cellstr(arg1);
131 end
132 if ~iscellstr(arg1)
133 %At this point we should have a cell array. Otherwise error.
134 error(message('MATLAB:datenum:NotAStringArray'));
135 end
136 icu_dtformat = cnv2icudf(format);
137 showyr = strfind(icu_dtformat,'y');
138 if ~isempty(showyr)
139 wrtYr = numel(showyr);
140 checkYr = diff(showyr);
141 if any(checkYr~=1)
142 error(message('MATLAB:datenum:YearFormat'));
143 end
144 switch wrtYr
145 case 4,
146 icu_dtformat = strrep(icu_dtformat,'yyyy','yy');
147 case 3,
148 icu_dtformat = strrep(icu_dtformat,'yyy','yy');
149 end
150 end
151 if (isempty(format))
152 n = datenummx(datevec(arg1,pivot));
153 else
154 if (isempty(pivot))
155 n = dtstr2dtnummx(arg1,icu_dtformat);
156 else
157 n = dtstr2dtnummx(arg1,icu_dtformat,pivot);
158 end
159 end
160 else
161 n = datenummx(arg1,arg2,arg3);
162 end
1 163 case 6, n = datenummx(arg1,arg2,arg3,h,min,s);
164 otherwise, error(message('MATLAB:datenum:Nargin'));
165 end
166 catch exception
167 if (nargin == 1 && ~isdatestr)
168 identifier = 'MATLAB:datenum:ConvertDateNumber';
169 elseif (nargin == 1 && isdatestr) || (isdatestr && any(isdateformat))
170 identifier = 'MATLAB:datenum:ConvertDateString';
171 elseif (nargin > 1) && ~isdatestr && ~any(isdateformat)
172 identifier = 'MATLAB:datenum:ConvertDateVector';
173 else
174 identifier = exception.identifier;
175 end
176 newExc = MException( identifier,'DATENUM failed.');
177 newExc = newExc.addCause(exception);
178 throw(newExc);
179 end