Calculate number of hours below a threshold temperature
조회 수: 3 (최근 30일)
이전 댓글 표시
I have a big timetable with temperature recorded every 10 minutes. I want to calculate the number of hours per day below a threshold temperature. Any ideas? The timetable is important because my original data is missing some timesteps, and I use retime() to fill in the blanks.
I tried using a for loop along with an if statement, but they don't seem to work with timetables.
I also tried converting the timetable back to an array, but ran into difficulties. My guess is that I'm missing the easy way to do this.
Thanks!
댓글 수: 0
채택된 답변
Kelly Kearney
2018년 7월 19일
I think you should be able to accomplish this by retiming twice; once to fill in any gaps with whatever method you prefer, and the second time to aggregate over each day. If you assume each measurement is representative of a full 10 minutes, then you can simply sum the number of points per day that meet the threshold criteria.
First we build an example timetable with ~10-minute data with some gaps
t = datetime(2018,1,1) + days(0:minutes(10):days(2))';
temp = rand(size(t))*15 - 2;
T = timetable(t, temp);
T = T(rand(size(t))>0.1,:);
Now retime:
dt = minutes(10);
thresh = 0;
T2 = retime(T,'regular', 'linear', 'timestep', dt);
T3 = retime(T2,'daily',@(x) hours(sum(x<thresh)*dt));
댓글 수: 4
Kelly Kearney
2018년 7월 20일
Trying to do run-length calculations in a one-liner gets a bit complicated, so I would write a separate subfunction for that purpose.
T2 = retime(T,'regular', 'linear', 'timestep', dt);
T3 = retime(T2, 'daily', @(x) consectime(x,thresh,dt));
function y = consectime(v, th, dt)
[b,n] = RunLength(v > th);
y = hours(max(n(b==1)) * dt);
end
The T3.temp field now holds the length (in hours) of the longest consecutive period over the threshold, per day. I use the RunLength function from the FEX to do a lot of the heavy lifting here.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!