How to add hours to the time data of one day
7 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Star Strider
on 10 Apr 2022
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 Comments
More Answers (1)
Campion Loong
on 13 Apr 2022
Edited: Campion Loong
on 13 Apr 2022
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 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!