MATLAB: Adding datenum to plots

datenumdatetick

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.
plot(data(1:2924,2))
datetick('x',11)

Best Answer

% 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'] ;
figure
plot(data(:,1),data(:,2))
datetick('x','yyyy','keeplimits')
Related Question