CONVERTING 6 HOURLY DATA TO DAILY DATA
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tanmoyee Bhattacharya
el 3 de Nov. de 2019
Respondida: Roofus Milton
el 4 de Nov. de 2019
I have 6 hourly data in following format:
01.01.1990-00:00:00 60
01.01.1990-06:00:00 70
01.01.1990-12:00:00 100
01.01.1990-18:00:00 70
01.02.1990-00:00:00 23
01.02.1990-06:00:00 60
01.02.1990-12:00:00 34
01.02.1990-18:00:00 56
.
.
.
.
For daily conversion I have to add four dataset for each day. How to do it in matlab?
0 comentarios
Respuesta aceptada
Walter Roberson
el 3 de Nov. de 2019
T = readtable('YourFileName', 'readvariablenames', false);
daily_totals = sum(reshape(T{:,2}, 4, 1));
This assumes that there are exactly 4 entries available for each day. If that is not true, especially if there are some missing entries, then I recommend converting into timetable() object and use retime()
2 comentarios
Walter Roberson
el 3 de Nov. de 2019
num = xlsread('my filename.xlsx');
daily_totals = sum(reshape(num(:,end), 4, 1));
It is not immediately clear whether the entries such as 01.01.1990-00:00:00 are text or Excel date number, so it is not immediately clear whether the column will only appear in the second or third outputs of xlsread() or would appear in the first column. To get around that uncertainty I ask for the last column.
Más respuestas (1)
Roofus Milton
el 4 de Nov. de 2019
Tanmoyee-
I made a slight modification to Walter's code to make the reshape parameters dynamic.
% store number of samples per day, needed for reshape
samplesPerDay = 4;
% dates provided in sample, plus an additional day
dates = {'01.01.1990-00:00:00', '01.01.1990-06:00:00', '01.01.1990-12:00:00', '01.01.1990-18:00:00', ...
'01.02.1990-00:00:00', '01.02.1990-06:00:00', '01.02.1990-12:00:00', '01.02.1990-18:00:00', ...
'01.03.1990-00:00:00', '01.03.1990-06:00:00', '01.03.1990-12:00:00', '01.03.1990-18:00:00'}';
% convert the date character strings to numbers
dNums = datenum(dates, 'dd.mm.yyyy-HH:MM:SS');
% remove the time element through rounding
dNumsRounded = floor(dNums);
% calculate the unique number of days, needed for reshape
numDays = length(unique(dNumsRounded));
% numbers provided in sample, the last 4 numbers are in addition to your sample
nums = [60 70 100 70 23 60 34 56 28 65 39 61]';
% combine the two data vectors into a matrix
data = [dNums, nums];
% reshape the data
newData = reshape(data, [samplesPerDay, numDays, 2])
newData =
newData(:,:,1) =
726834.00 726865.00 726893.00
726834.25 726865.25 726893.25
726834.50 726865.50 726893.50
726834.75 726865.75 726893.75
newData(:,:,2) =
60.00 23.00 28.00
70.00 60.00 65.00
100.00 34.00 39.00
70.00 56.00 61.00
output = sum(newData(:, :, 2))
output = 1×3
300.00 173.00 193.00
0 comentarios
Ver también
Categorías
Más información sobre Calendar 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!