How to calculate the quantiles/percentiles values for each hour?
26 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
回答(1 个)
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
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...
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Preprocessing Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!