error in prctile function?
14 ビュー (過去 30 日間)
古いコメントを表示
I'm creating my own percentile function and wanted to compare it to the prctile function available in MATLAB.
I am pretty sure I am doing things right but I am getting different values than prctile.
data = [1 2 3 4 5];
p = 0:100;
y1 = prctile(data,p);
y2 = my_function(data,p);
My values are linear (1,1.04,1.08,etc.) as one might expect but the values from MATLAB's prctile are not. What gives?
0 件のコメント
採用された回答
Jonas
2022 年 11 月 24 日
did you read the documentation? there is an example given for the interpolation and how the given numbers may be distributed. You should also ask yourself, what the 0% border (which contains no data point of the given data) is.
So Matlab thinks you have to have at least one data point inside the smallest percentage. So at least 1 data point, which equals 20% when you have 5 data points. In addition, Matlab centers the given Data, so 1:5 are not percentile 20:20:100 but 10:20:90. If you ask for percentile bigger/smaller that range, Matlab rounds it to the smallest/greatest acceptable percentiles (here 10% and 90%)
data = [1 2 3 4 5];
y1 = prctile(data,10:20:90)
y1 = prctile(data,20:20:100) % you can see that matlab interpolates and caps at the same time
y1 = prctile(data,[0 10:20:90 100]) % here a similar example
0 件のコメント
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!