How to calculate the quantiles/percentiles values for each hour?

35 ビュー (過去 30 日間)
Kofial
Kofial 2021 年 1 月 21 日
コメント済み: dpb 2022 年 8 月 18 日
I calculate with this code the quantile points of all the data.
Data=[1.5 2.3 2.5 4 6.2 7.1 8];
First_data = quantile(Data, [0 0.25 0.50 0.75 1])';
QuantilePoints = {'Minimum', '25th percentile', '50th percentile', '75th percentile', 'Maximum'}';
T = table(QuantilePoints, First_data);
disp(T)
How can I calculate the quantile points for every hour? The hour is in the datetime format like below.
Time_datenum={'20-Apr-2020 11:06:00','20-Apr-2020 11:20:10','20-Apr-2020 11:45:30','20-Apr-2020 12:07:00','20-Apr-2020 12:35:40','20-Apr-2020 12:40:50','20-Apr-2020 13:07:00'};
Time_datetime = datetime(Time_One,'InputFormat','dd-MM-yyyy HH:mm:ss');

回答 (1 件)

dpb
dpb 2021 年 1 月 21 日
編集済み: dpb 2021 年 1 月 21 日
Use grouping variables and splitapply or put into a table or timetable and then rowfun and/or retime (timetable) are also options.
Earlier today I showed an example on another variable, but principles still apply <Splitting-data-array-into-sub-arrays#>
  8 件のコメント
Maria Jacob
Maria Jacob 2022 年 8 月 18 日
編集済み: Maria Jacob 2022 年 8 月 18 日
Thanks for checking. I literally started using timetables just a few weeks ago, and due to other commitments I haven't been able to dedicate it a lot of hours.
So yes, what I was saying is doing retime(data,'monthly',@prctile) is not allowed, because I need to specified what % I want. Sorry for not being more clear.
With respect to creating the custom function, what I tried is using rowfun, in the following way (which is a copy of an example in the Matlab documentation):
5prc = @(x) prctile(x,5);
B = rowfun(5prc,data,'GroupingVariable','month(data.Time)','OutputVariableName','5th prc');
And I get a parsing error at ) for the definition of 5prc, it literally says: Parse error at ')': usage might be invalid MATLAB syntax.
Regardless, I will try your way, since you have shown it works. I wish I had more time to tried myself before asking, sorry...
EDIT:
OMG, I'm an IDIOT!! It's the 5...
dpb
dpb 2022 年 8 月 18 日
Chuckles...we all do such things from time to time...

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by