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에서 Data Preprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!