Daily mean of a hourly dataset

6 ビュー (過去 30 日間)
Murielle van Pampus
Murielle van Pampus 2022 年 1 月 6 日
コメント済み: Simon Chan 2022 年 1 月 6 日
Hi,
To determine the annual daily maximum of a dataset, as attached by this question I have to convert my data. My data set is as follows:
[Year, Month, Day, Hour, info1, info2,info3,....] and is a txt-file.
To combine the different time info, I used the function datetime, as this would transfer the four columns into one Time-column. But as I try, the error "All input arguments must be tables" appears. Therefore, I was wondering what I'm doing wrong in my code.
Secondly, I would like to average my data over the days, so I get one data point for every day. As if I have the average of every day, I need to determine the yearly maximum, which I tried with the retime-function.
Can someone help me with what I am doing wrong?
clear; clc; close all;
filename = 'data_1991_2020_edited.txt';
delimiterIn = ' ';
headerlinesIn = 1;
Data = importdata(filename,delimiterIn,headerlinesIn);
%[A,delimiterOut]=importdata(filename)
Data1 = readtable(filename);
% Create datetime array
time_dep = datetime([Data1(:,1),Data1(:,2),Data1(:,3),Data1(:,4),zeros(size(Data1,1),1),zeros(size(Data1,1),1)]);
%TData = timetable(Times, Data1(:,6));
%YrMean = retime(TData, 'yearly', 'max'); % Yearly Maximum
%Max = [YrMean.Times.Year YrMean.Var1]

採用された回答

Simon Chan
Simon Chan 2022 年 1 月 6 日
編集済み: Simon Chan 2022 年 1 月 6 日
Try the following:
filename = 'data_2001_2010.txt';
Data1 = readtable(filename,'VariableNamingRule','preserve');
Data1(:,1)=[]; % Remove the 1st column
Data1.YYYYMMDD=datetime(string(Data1.YYYYMMDD),'InputFormat','yyyyMMdd'); % Convert to datetime format
Gmean=groupsummary(Data1,"YYYYMMDD",'day',"mean"); % Calculate daily mean
  10 件のコメント
Murielle van Pampus
Murielle van Pampus 2022 年 1 月 6 日
Would you also know how to remove duplicates if the max value occured multiple times in a year. So for example the value of FH of 180 ocured 5 times in december. Currently it gives 5 values of 180 for 2020. Is there a argument to remove duplicates?
Simon Chan
Simon Chan 2022 年 1 月 6 日
You need to state the criteria to remove duplicates since the values on other columns are different.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by