calculate statistics every quarter of an hour on time series data
조회 수: 1 (최근 30일)
이전 댓글 표시
I have time series data in a table labeled with the date and time. I want to calculate statistics on every quarter of an hour. The number of observations every quarter of an hour can vary. The code I have takes a long time as the time series can be large.
D = datevec(x.DateTime,'yyyy-mm-dd HH:MM:SS');
quarter = zeros(N,1);
quarter(D(:,5)>00 & D(:,5)<=15) = 1;
quarter(D(:,5)>15 & D(:,5)<=30) = 2;
quarter(D(:,5)>30 & D(:,5)<=45) = 3;
quarter(D(:,5)>45 & D(:,5)<=60) = 4;
quarter(D(:,5)==00) = 4;
qnow = quarter(1);
while ~isempty(quarter)
stop = find(quarter~=qnow,1)-1;
x_temp = x(1:stop,:);
x(1:stop,:) = [];
quarter(1:stop) = [];
if qnow < 4
qnow = qnow + 1;
else
qnow = 1;
end
length(quarter)
end
At each iteration I can calculate statistics on x_temp and save to another table. Is there a more efficient way to do this?
Thanks,
댓글 수: 0
답변 (1개)
Azzi Abdelmalek
2015년 6월 27일
x=datenum('2015-01-01 00:00:0'):1/(24*12):datenum('2015-01-01 2:00:0')
y=datestr(x,'yyyy-mm-dd HH:MM:SS')
D = datevec(y,'yyyy-mm-dd HH:MM:SS')
time=D(:,5);
idx1=time>=00 & time<=15
idx2=time>15 & time<=30
idx3=time>30 & time<=45
idx4=time>45 & time<=60
v={idx1 idx2 idx3 idx4}
ii1=sort(cell2mat(cellfun(@(x) strfind([0 x' 0],[0 1]),v,'un',0)))
ii2=sort(cell2mat(cellfun(@(x) strfind([0 x' 0],[1 0])-1,v,'un',0)))
You can use all the indices of different groups in ii1 and ii2.
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!