Main Content

dateaxis

Convert serial-date axis labels to calendar-date axis labels

Description

dateaxis(Tickaxis,DateForm,StartDate) replaces axis tick labels with date labels.

example

Examples

collapse all

This example shows how to use dateaxis to replaces axis tick labels with date labels on a graphic figure.

Convert the x-axis labels to an automatically determined date format.

dateaxis('y', 6)

Convert the y-axis labels to the month/day format.

dateaxis('x', 2, datetime(1999,3,3))

Convert the x-axis labels to the month/day/year format. The minimum x-tick value is treated as March 3, 1999.

dateaxis('x', 2, datetime(1999,3,3))

Figure contains an axes object. The axes object is empty.

Input Arguments

collapse all

(Optional) Determines which axis tick labels —x, y, or z— to replace, specified as a character vector.

Data Types: char

(Optional) Defines which date format to use, specified as an integer from 0 to 17.

If no DateForm argument is entered, this function determines the date format based on the span of the axis limits. For example, if the difference between the axis minimum and maximum is less than 15, the tick labels are converted to three-letter day-of-the-week abbreviations (DateForm = 8).

DateForm

Format

Description

0

01-Mar-1999 15:45:17

day-month-year hour:minute:second

1

01-mar-1999

day-month-year

2

03/01/99

month/day/year

3

Mar

month, three letters

4

M

month, single letter

5

3

month

6

03/01

month/day

7

1

day of month

8

Wed

day of week, three letters

9

W

day of week, single letter

10

1999

year, four digits

11

99

year, two digits

12

Mar99

month year

13

15:45:17

hour:minute:second

14

03:45:17 PM

hour:minute:second AM or PM

15

15:45

hour:minute

16

03:45 PM

hour:minute AM or PM

17

95/03/01

year month day

Refer to the MATLAB® set command for information on modifying the axis tick values and other axis parameters.

Data Types: double

(Optional) Assigns the date to the first axis tick value, specified as a scalar datetime, string, or date character vector.

The default StartDate is the lower axis limit converted to the appropriate date number. For example, a tick value of 1 is converted to the date 01-Jan-0000. Entering StartDate as '06-apr-1999' assigns the date April 6, 1999 to the first tick value and the axis tick labels are set accordingly.

To support existing code, dateaxis also accepts serial date numbers as inputs, but they are not recommended.

Data Types: char | string | datetime

Version History

Introduced before R2006a

expand all