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

24 visualizzazioni (ultimi 30 giorni)
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');

Risposte (1)

dpb
dpb il 21 Gen 2021
Modificato: dpb il 21 Gen 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 Commenti
Maria Jacob
Maria Jacob il 18 Ago 2022
Modificato: Maria Jacob il 18 Ago 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 il 18 Ago 2022
Chuckles...we all do such things from time to time...

Accedi per commentare.

Categorie

Scopri di più su Data Preprocessing in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by