X-axis data in years

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.

 Risposta accettata

the cyclist
the cyclist il 8 Dic 2012
Modificato: the cyclist il 8 Dic 2012

0 voti

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

2 Commenti

the cyclist
the cyclist il 9 Dic 2012
EDIT: @Thomas, I moved your comment here, rather than having it listed as another "answer", where you had placed it.]
Thank you worked like a charm, one thing though it did in increments of 3, is there any way to force it to display each year? I think my problem was adding datetick after the plot function.
Before you do the datetick command, you should be able to use the command
> set(gca,'XTick',<put datenums here>)
to set the ticks exactly where you want them (for example at the year marks). Then, when you use datetick() function, be sure to use the 'keepticks' option.

Accedi per commentare.

Più risposte (0)

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by