How to select a repetitive range?
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all,
I have a data from 1 to 8760 representing the hours of the year. I want to select for instance 11 to 17 and repeat it every 24 hours (selecting the same range in the next day, the value will be added by 24 so that it jumps to 11 o'clock in the second day and so on). How should I do that?
Thanks
댓글 수: 3
Peter Perkins
2021년 9월 1일
Actually, this is super easy using a timetable:
>> hourly = timetable(datetime(2021,1,1,0:8759,0,0)',rand(8760,1));
>> t = datetime(2021,1,1:365) + hours(11:17)'; % implicit expansion: row + column
>> hourly_11_17 = hourly(t,:);
>> head(hourly_11_17)
ans =
8×1 timetable
Time Var1
____________________ ________
01-Jan-2021 11:00:00 0.61605
01-Jan-2021 12:00:00 0.89185
01-Jan-2021 13:00:00 0.71641
01-Jan-2021 14:00:00 0.86522
01-Jan-2021 15:00:00 0.83825
01-Jan-2021 16:00:00 0.019567
01-Jan-2021 17:00:00 0.33124
02-Jan-2021 11:00:00 0.38599
채택된 답변
Walter Roberson
2021년 3월 22일
data_day = reshape(YourData, 24, [], size(YourData,2));
data_day(11:17, :, :)
You could reshape() that to [], size(data_day,3) if you want to push the chunks back together again, but I suspect having it by hour will be more useful.
Or
idx = (11:17).' + (0:24:size(YourData,1)-1);
selected_data = YourData(idx,:)
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
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!