Common MATLAB Time Functions

Source: Internet
Author: User

1. Now returns the current date value (the integer part of this number indicates the number of days from January 1, January 1 to that day, a.m., and the fractional part indicates the specific time)
Eg.
T = now
T = 7.3354e + 005
2. Convert the datestr date to the character form
The call format datestr (date, dateform) date is the date value to be converted, and dateform is the date format parameter (for specific parameter values, see help datestr for help)
Dateform parameter description

Table 1: Standard MATLAB Date Format Definitions
 
Number string example
========================================================== ==========================================
0 'dd-mmm-yyyy hh: mm: ss' 01-Mar-2000 15:45:17
1 'dd-mmm-yyyy '01-Mar-2000
2 'Mm/DD/yy '03/01/00
3 'mmm' MAR
4 'M' m
5 'mm' 03
03/01mm/dd'
7 'dd' 01
8 'ddd 'wed
9 'D' W
10 'yyyy' 2000
11 'yy' 00
12 'mmmyy' mar00
13 'hh: mm: ss' 15:45:17
14 'hh: mm: SS Ps' 3:45:17
15' hh: Mm'
16 'hh: Mm Ms' pm
17 'qq-yy' Q1-96
18 'qq' Q1
19 'dd/mm' 01/03
20 'dd/mm/yy '01/03/00
21 'mmm. DD, yyyy hh: mm: ss' mar.01, 2000 15:45:17
22 'mmm. DD, yyyy' mar.01, 2000
23 'Mm/DD/yyyy' 03/01/2000
24 'dd/MM/yyyy' 01/03/2000
25'yy/MM/dd' 00/03/01
26 'yyyy/MM/dd' 2000/03/01
27 'qq-yyyy' Q1-1996
28 'mmmyyyy' mar2000
29 (ISO 8601) 'yyyy-mm-dd' 2000-03-01
30 (ISO 8601) 'yyyymmddthhmmss '20000301t154517
31 'yyyy-mm-dd hh: mm: ss' 2000-03-01 15:45:17
 
Table 2: Free-Form Date Format symbols

Symbol interpretation of format symbol
========================================================== ==========================================
Yyyy full year, e.g. 1990,200 0, 2002
YY partial year, e.g. 90, 00, 02
Mmmm full name of the month, according to the calendar locale, e.g.
"March", "maid" in the UK and USA English locales.
Mmm first three letters of the month, according to the calendar
Locale, e.g. "Mar", "APR" in the UK and USA English locales.
MM numeric month of year, padded with leading zeros, E.G.../03 /..
Or.../12 /..
M capitalized first letter of the month, according to
Calendar locale; for backwards compatibility.
Dddd full name of the weekday, according to the calendar locale, e.g.
"Monday", "Tuesday", for the UK and USA calendar locales.
Ddd first three letters of the weekday, according to the calendar
Locale, e.g. "mon", "Tue", for the UK and USA calendar locales.
Dd numeric day of the month, padded with leading zeros, e.g.
05/... or 20 /../..
D capitalized first letter of the weekday; for backwards
Compatibility
HH hour of the day, according to the time format. In case the time
Format am | PM is set, HH does not pad with leading zeros. In
Case am | PM is not set, display the hour of the day, padded
With leading zeros. e. g pm, which is equivalent;
Am, which is equivalent.
MM minutes of the hour, padded with leading zeros, e.g. 10: 15,
10: 05, 10: 05 am.
SS second of the minute, padded with leading zeros, e.g. 10:15:30,
10:05:30, 10:05:30 AM.
Fff milliseconds field, padded with leading zeros, e.g.
10:15:30. 015.
PM set the time format as time of morning or time of afternoon. AM
Or PM is appended to the date string, as appropriate.

 

 

Eg.

> T = now; datestr (T, 0)

Ans = 09-may-2008 21:07:23

3. Date converts a string to a date value.
Call Syntax: date (year, month, day)
Datenum (year, month, day, hour, minute, second)
Eg.

> T = now; datestr (T, 0)

Ans = 09-may-2008 21:07:23

> Datenum (ANS)
Ans = 7.3354e + 005

>

4. datevec converts the format date character specified in datestr into a numerical vector containing the date component.
Eg.
> C = datevec ('09-may-2008 21:07:23 ')

C = 2008 5 9 21 7 23
5. weekday identifies the specific day and week from a date value or string.
Eg.
> [D, w] = weekday (7.3354e + 005) d = 2
W = mon> [d, w] = weekday ('21-Dec-2008 ') d = 1
W = sun6.eomday returns the number of the last day of any month.
Syntax for calling: eomday (year, month) requires the year parameter because of the existence of a leap year.
Eg.

> Eomday)

Ans = 29

> Eomday (2007,2)

Ans = 28

7. Generate the calendar of the specified month using the calendar.
Eg
> Calendar (date)
May 1, 2008
S m tu w th f s
0 0 0 0 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
0 0 0 0 0 0
> Calendar)
May 1, 2008
S m tu w th f s
0 0 0 0 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
0 0 0 0 0 0>
Supplement: Date returns the string of the date of the current day.
Eg.
> Dateans = 09-may-20088.tic. The time required for the execution of a set of MATLAB operation commands can be calculated using the combined use of TOC and TOC.
Eg.
> TIC; plot (RAND (, 5); TOC
Elapsed time is 0.078000 seconds.
In addition, MATLAB provides cputime and etime (see the help document for specific usage) to calculate the CPU time occupied by an operation.
Eg.
> T0 = cputime; myoperation; cputime-t0
Ans = 0.1400
> T1 = clock; myoperation; etime (clock, T1)
Ans = 11.2800
Note: myoperation is a user-defined script file.
> T0 = cputimet0 = 53.8125

> T1 = cputimet1 = 54.0313

> Deltat = t1-t0

Deltat = 0.2188

>
T1 = clockt1 = 1.0e + 003*2.0080 0.0050 0.0090
0.0460 0.0254> deltat = etime (T1, T0) deltat = 9.9060>
9. Set the coordinates of datetick to the time tag eg.
> T = (1900: 10: 1990 )';
> P = [100 200 150 350 200 400 500 30 100];
> Plot (datenum (T, 1, 1), P );
> Datetick ('x', 'yyyy ')
> Title ('test time tip ')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.