How to add hours to the time data of one day
20 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
peter huang
el 10 de Abr. de 2022
Editada: Campion Loong
el 13 de Abr. de 2022
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 comentarios
Respuesta aceptada
Star Strider
el 10 de Abr. de 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 comentarios
Más respuestas (1)
Campion Loong
el 13 de Abr. de 2022
Editada: Campion Loong
el 13 de Abr. de 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 comentarios
Ver también
Categorías
Más información sobre Dates and Time en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!