How to add hours to the time data of one day
조회 수: 7 (최근 30일)
이전 댓글 표시
i have raw data timeseries (excel column A)
i want use marlab add hours to the time data (like column B)
how to addtion hours in day by day timeseries
댓글 수: 0
채택된 답변
Star Strider
2022년 4월 10일
The hours would have to be added as a column vector, and the other variables repeated so that all the rows were the same. It is straightforward to repeat the first ‘n’ (here 6) rows, and then concatenate them to the rest of original table.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/959420/time_file.xlsx')
NewFirstRows = repmat(T1(1,:), 6, 1); % Duplicate The First Row
NewFirstRows.Var1 = NewFirstRows.Var1+ hours(0:4:23)'; % Add Hours To The First Variable
T1 = [NewFirstRows; T1(2:end,:)] % Concatenate
You would need to determine how the replications were done. and what rows were to be replicated. This is simply an example of how I would do it.
.
댓글 수: 0
추가 답변 (1개)
Campion Loong
2022년 4월 13일
편집: Campion Loong
2022년 4월 13일
Alternatively, if you want to 'expand' every day into 24 hours as in your file, you could do this in two steps (starting with a trimmed down example of 5 days)
% Example 5-row timetables for first five days of April
tt = array2timetable(randi(100,5),'RowTimes',datetime(2022,4,1:5)')
% Repeat each row 24 times
tt = repelem(tt,24,1);
% Add 0 to 23 hours to each day's time
tt.Time = tt.Time + repmat(hours(0:23)', 5, 1)
댓글 수: 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!