필터 지우기
필터 지우기

Plotting a year by hour

조회 수: 1 (최근 30일)
Claire
Claire 2011년 2월 19일
I'm attempting to plot a year by date and hour. Someone suggested the following code:
D = datevec(datenum(1992,1,1:1/24:366));
which produces a years worth of data plus one hour, so I've got 01-01-1992, 0:00:00 to 31-12-1992 0:00:00. So I've got 8761 rows of data for my hours, but only 8760 rows of input data. If anyone can point me in the right direction that would be great. Thank you.

채택된 답변

Matt Fig
Matt Fig 2011년 2월 19일
Also, you realize 1992 was a leap year? Is that the year your data was taken? If it is for a generic year, why not use:
D2 = datevec(datenum(1993,1,1:1/24:365+23/24)); % makes 8760 rows
  댓글 수: 1
Claire
Claire 2011년 2월 22일
Thank you, that's great, much appreciated.

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

추가 답변 (2개)

Matt Tearle
Matt Tearle 2011년 2월 19일
So the issue is how to extract the first 8760 elements of a vector of 8761 points? That's easy enough:
plot(x(1:end-1),y)

Matt Tearle
Matt Tearle 2011년 2월 19일
If you're starting just with data and the knowledge that it was recorded hourly throughout a given year, why not just do something like:
t = datenum(yr,1,1) + (0:(length(x)-1))/24;
D = datevec(t);
Or, alternatively
tstart = datenum(yr,1,1);
tend = datenum(yr+1,1,1) - 1/24;
n = 24*(tend-tstart) + 1;
if n==length(x)
t = linspace(tstart,tend,n);
% etc
else
error('wrong number of data points')
end

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by