MATLAB: Prctile function vs excel percentile

prctile

Hi,
when I run the below,
A = [ 0.02; 0.01 ; 0.01; 0.01 ; 0.04 ]; B = prctile(A,99.95);
I get B = 0.0400, which seems rounded.
In excel the same percentile function produces a result of 0.03996
Is there a way to show a less rounded result in matlab? Any other function or calculation in matlab e.g. 65/43, will produce a result (1.5116) that doesn't round the decimals like prctile does.
(even if I try "format long" the result will still be 0.040000000…)
Many thanks

Best Answer

This is the behavior as it is designed to do. READ THE HELP.
1) The sorted values in X are taken as the 100*(0.5/N), 100*(1.5/N),
..., 100*((N-0.5)/N) percentiles.
2) Linear interpolation is used to compute percentiles for percent
values between 100*(0.5/N) and 100*((N-0.5)/N)
3) The minimum or maximum values in X are assigned to percentiles
for percent values outside that range.
Thus, for 5 data points, anything above the 90th percentile is returned as the highest element in your vector.
In Excel, the difference is it is NOT the SAME percentile function. Two different people wrote those codes, to two different sets of specifications. The Excel percentile function treats 0.04 as the 100% point. In MATLAB, it is treated as the 90th percentile.
Think of it as if you put each of those numbers into bins. In MATLAB, when you have 5 numbers, MATLAB assigns the 80-100% bin to 0.04, the highest element in the vector, but above 90%, it chooses not to extrapolate. This was clearly a design choice.
B = prctile(A,79:100)
B =
Columns 1 through 11
0.029 0.03 0.031 0.032 0.033 0.034 0.035 0.036 0.037 0.038 0.039
Columns 12 through 22
0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04 0.04
Never make the mistake of assuming that two functions in two different languages are the same, that they should produce the same results, even if they have similar names and goals.