Adding datenum to plots

24 vues (au cours des 30 derniers jours)
David du Preez
David du Preez le 12 Mai 2017
Hi. I have 2924 x 2 matrix. In column 1 is the daily datenum value from 2007-2016. These in are not necessarily continues as some data points have been removed. In column 2 is the data. I want to plot the data and indicate the years on the x-axis. I have tried this but it doens't work.

Réponse acceptée

KSSV le 12 Mai 2017
% make some random data
startDate = datenum('02-01-1962');
endDate = datenum('11-15-2012');
x = datenum(linspace(startDate,endDate,50));
y = rand(1,50) ;
data = [x' y'] ;

Plus de réponses (1)

Peter Perkins
Peter Perkins le 12 Mai 2017
In MATLAB R2014b or later (and especially in R2016b or later), consider using datetimes, not datenums.
startDate = datetime('01-Feb-1962');
endDate = datetime('15-Nov-2012');
x = linspace(startDate,endDate,50);
y = rand(1,50);
This figure automatically updates the ticks as you pan and zoom.


En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by