필터 지우기
필터 지우기

CONVERTING 6 HOURLY DATA TO DAILY DATA

조회 수: 3 (최근 30일)
Tanmoyee Bhattacharya
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?

채택된 답변

Walter Roberson
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
Tanmoyee Bhattacharya
Tanmoyee Bhattacharya 2019년 11월 3일
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 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
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

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

태그

제품


릴리스

R2013a

Community Treasure Hunt

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

Start Hunting!

Translated by