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 Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

질문:

2012년 12월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by