data extraction from a time series

조회 수: 9 (최근 30일)
Binu
Binu 2022년 2월 1일
답변: Walter Roberson 2022년 2월 1일
Hi I have a time seris data. I want to extract the data , for example, from 06:01:01 to 20:01:01 everyday. I have attached a few days of data as a sample.
Thank you

채택된 답변

Walter Roberson
Walter Roberson 2022년 2월 1일
I had to guess that you wanted to exclude 20:01:01 itself.
I wonder if what you would really want is "after 6 am (excluding 6 am), up to and include 8 pm" ? Or maybe 6 am (inclusive) up to but excluding 8 pm ?
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/880370/test%20data.xlsx';
opt = detectImportOptions(filename, 'readvariablenames', false);
opt = setvartype(opt, 1, 'datetime');
opt = setvaropts(opt, 1, 'InputFormat', 'uuuu-MM-dd HH:mm:ss');
T = readtable(filename, opt);
[h, m, s] = hms(T{:,1});
d = duration(h, m, s);
starttime = duration(06,01,01);
endtime = duration(20,01,1);
mask = isbetween(d, starttime, endtime, 'openright');
selected_T = T(mask,:);
selected_T(end-10:end,:)
ans = 11×3 table
Var1 Var2 Var3 ___________________ __________ _____ 2021-07-03 15:01:01 {0×0 char} 0.259 2021-07-03 16:01:01 {0×0 char} 0.266 2021-07-03 17:01:01 {0×0 char} 0.239 2021-07-03 18:01:01 {0×0 char} 0.249 2021-07-03 19:01:01 {0×0 char} 0.251 2021-07-04 06:01:01 {0×0 char} 0.356 2021-07-04 07:01:01 {0×0 char} 0.334 2021-07-04 08:01:01 {0×0 char} 0.321 2021-07-04 09:01:01 {0×0 char} 0.319 2021-07-04 10:01:01 {0×0 char} 0.373 2021-07-04 11:01:01 {0×0 char} 0.371

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by