Azzera filtri
Azzera filtri

CONVERTING 6 HOURLY DATA TO DAILY DATA

3 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Walter Roberson
Walter Roberson il 3 Nov 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 Commenti
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya il 3 Nov 2019
Thank you sir.But I am using matlab 2013a where the readtable is not avialable.If I am using xlsread then I take the values:
60
70
100
70
23
60
34
56
T=xlsread('my filename.xlsx');
daily_totals = sum(reshape(T{:,2}, 4, 1));
The error is coming
Cell contents reference from a non-cell array object.
How to do the dailysum by using matlab2013a?
Walter Roberson
Walter Roberson il 3 Nov 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.

Accedi per commentare.

Più risposte (1)

Roofus Milton
Roofus Milton il 4 Nov 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

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Tag

Prodotti


Release

R2013a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by