Effacer les filtres
Effacer les filtres

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

35 vues (au cours des 30 derniers jours)
Kofial
Kofial le 21 Jan 2021
Commenté : dpb le 18 Août 2022
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');

Réponses (1)

dpb
dpb le 21 Jan 2021
Modifié(e) : dpb le 21 Jan 2021
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 commentaires
Maria Jacob
Maria Jacob le 18 Août 2022
Modifié(e) : Maria Jacob le 18 Août 2022
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 le 18 Août 2022
Chuckles...we all do such things from time to time...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Preprocessing Data dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by