How to add hours to the time data of one day
8 次查看(过去 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!