MATLAB Examples

This is an example of how to create a datetime plot in MATLAB®.

Read about the datetime function and the XAxis property in the MATLAB documentation. This function is available in R2016b or newer.

For more examples, go to MATLAB Plot Gallery

% Check version
if verLessThan('matlab','9.1')
    error('heatmap is available in R2016b or newer.')

% Load bike ride summary data
load RideSummary byDate

% Plot the mean bike ride duration versus date
plot(byDate.Date, byDate.MeanDuration)

% Change limits and date format
limits = [datetime(2012,7,1) datetime(2012,8,31)];
ax = gca;
ax.XAxis.TickLabelFormat = 'MMMM dd';
ax.XAxis.TickLabelRotation = 40;

% Add labels and title
ylabel('Mean Ride Duration')
title('Mean Ride Duration between July and August 2012')