CONVERTING 6 HOURLY DATA TO DAILY DATA
2 ビュー (過去 30 日間)
古いコメントを表示
Tanmoyee Bhattacharya
2019 年 11 月 3 日
回答済み: Roofus Milton
2019 年 11 月 4 日
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 件のコメント
採用された回答
Walter Roberson
2019 年 11 月 3 日
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 件のコメント
Walter Roberson
2019 年 11 月 3 日
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.
その他の回答 (1 件)
Roofus Milton
2019 年 11 月 4 日
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 件のコメント
参考
カテゴリ
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!