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.

 採用された回答

the cyclist
the cyclist 2012 年 12 月 8 日
編集済み: the cyclist 2012 年 12 月 8 日

0 投票

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

2 件のコメント

the cyclist
the cyclist 2012 年 12 月 9 日
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.
the cyclist
the cyclist 2012 年 12 月 9 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by