필터 지우기
필터 지우기

plotting dates on x axis with labels auto generated for 1st Jan each year?

조회 수: 2 (최근 30일)
tombola
tombola 2011년 12월 8일
Hi, I'm plotting monthly data (generally the 16th of the month) over 20 or more years with the dates held as datenum's.
I'm generating my plots in code.
Does anyone know if there's a way to force/tell matlab to just have yearly points on the x axis, ie datetick('x',24,'keepticks'))
BUT have these autogenerated to the beginning of each year? So while the label will read say "2007", that point will be "01/01/2007".
Thanks for any help,
Tom.

답변 (2개)

Andrei Bobrov
Andrei Bobrov 2011년 12월 8일
EDIT (0:20 MDT 09.12.2011)
input data (e.g.):
n = 22*12-7;
datedata = datenum(bsxfun(@plus,[1990 12 16],[zeros(n,1) (0:n-1)' zeros(n,1)]));
solution:
n2 = diff(year(dte([1,end])));
x = datenum(bsxfun(@plus,[1991 1 1],[(0:n2-1)' zeros(n2,2)]));
plot(datedata,rand(numel(datedata),1));grid on
set(gca,'XTick',x);
datetick('x','yyyy','keepticks')

tombola
tombola 2011년 12월 8일
Hi, thanks. My dates will generally be the datenum equivalent of 16/12/1990 16/01/1991 16/02/1991 16/03/1991 16/04/1991 16/05/1991 16/06/1991 up to, say, 16/04/2012 (they may not all be the 16th, there could be others)
Is there any way to plot this data with labels 1990 1991 ... 2012 where each label is the 1st of Jan that year, ie, 01/01/1990 01/01/1991 ... 01/01/2012
Thanks a lot,
Tom

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by