필터 지우기
필터 지우기

Day of year to month

조회 수: 3 (최근 30일)
Claire
Claire 2011년 2월 9일
I have a years worth of data in the form of 1-365 (in a column of my matrix), and I want to change it to the days in a month, so I can plot a graph that is quicker to read, rather than having to work out, what month day 100 etc.. belongs to.
I'm sure it's really easy to do but I'm completely out of my depth.

답변 (5개)

Andreas Goser
Andreas Goser 2011년 2월 9일
I am not 100% sure, but maybe this example helps you
d2011=734504; % 734504 ist the first day of 2011 - example
v=d2011:d2011+100; % create a vector of 100 days
datestr(v) % see all the dates as strings - use for the figure
datevec(v) % can extract day of month

Claire
Claire 2011년 2월 9일
That does help thanks, but my problem now is that my data is hourly and so I need both time and data calculated to plot on my graph. I keep getting told that my vectors are different lengths, and I don't know how to rectify it.
  댓글 수: 4
Jan
Jan 2011년 2월 9일
Please show us the code and the error messages.
Claire
Claire 2011년 2월 9일
Sorry Doug, I'll change it,
It's currently as:
Day = Belmonte(:,2);
Year = Belmonte (:,1);
Hour = Belmonte (:,3);
Minute = Belmonte (:,4);
Second = Belmonte (:,5);
And what I want is Year, Month, Day, Hour, Minute, Second, and then to be able to do a date in the format of Y, M, D, H, M, S, so that I can plot it against my evapotranspiration data which has a result for every hour. Does that make any sense?

댓글을 달려면 로그인하십시오.


Brett Shoelson
Brett Shoelson 2011년 2월 9일
If you have 365 days, for instance, but no month information, you can simply increment the DAY position in datenum:
mydates = datenum(2011,1,1:365,h,m,s);
Or, if you want the y,m,d,h,m,s:
[y,m,d,h,m,s] = datevec(datenum(2011,1,1:365,h,m,s))
Cheers,
Brett
  댓글 수: 3
Brett Shoelson
Brett Shoelson 2011년 2월 9일
The answer doesn't change; you can specify the hour in the variable h.
Brett
Claire
Claire 2011년 2월 10일
I've changed my code to D= datevec(datenum(1992,1,1:365, 1:24 ,00,00) but I'm still only getting 365 results whereas I need the 365 x 24.
Thanks

댓글을 달려면 로그인하십시오.


Brett Shoelson
Brett Shoelson 2011년 2월 10일
How about this?
D = datevec(datenum(1992,1,1:1/24:365, 0,0,0));
Cheers,
Brett
  댓글 수: 1
Claire
Claire 2011년 2월 10일
Thanks, that's improved the situation somewhat, although it seems to be still not quite right.
I've used D = datevec(datenum(1992,1,1:1/24:366)); but my Evapotranspiration data has 8760 rows, and the code I've used results in 8761 rows, and only one hour of results for 31/12
i.e. 1992, 12, 31, 0, 0, 0. I know 1992 is a leap year, but the data appears to only have 365 days, which I suspect is confusing the matter, although of course 8760/365 is 24, so that's just confused me more.
Thanks again for all your help.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 2월 10일
I suspect you can skip all of this trouble and use datetick()
  댓글 수: 2
Claire
Claire 2011년 2월 10일
Can you expand on that please? Don't I need to have an equal number of plots on my x and y axis to use datetick successfully?
Walter Roberson
Walter Roberson 2011년 2월 10일
http://www.mathworks.com/help/techdoc/ref/datetick.html
datetick('x','mmm HH')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by