MATLAB: X-axis data in years

datex axis

Hello,
I have an unemployment report that reports data by the month, my data has a total of 215 points, each point representing one month. I've been trying to figure out how to have the x axis simply display the data in terms of years but I have not had any luck, looking for some help. Basically I would like the x-axis to begin with 1995 and end with 2012.
This is what I have so far:
clear all ; close all ; set(0,'DefaultFigureWindowStyle','normal') ; drawnow ; clc ;
display('Importing data……..'); unemployment = dataset('File', 'PE_Monthly.txt', 'delimiter', 'tab');
startdate = datenum('1995','yyyy') enddate = datenum('2012','yyyy') dt = linspace(startdate,enddate,12);
choice = menu('Unemployment Reports U3 vs. U6', '1995-2011', 'By year/month') if choice == 1 U6 = unemployment.U6RATE; U3 = unemployment.U3RATE; x = 1:215; plot (dt, U3, dt, U6);
I get some weird results on the x axis, nothing resembling 1995-2011.

Best Answer

It is presumably plotting the datenums, just as you told it to. ;-)
Try using the datetick() function after you plot.