how to calculate the 99th percentile in matlab

You can easily calculate the desired percentile in MATLAB using the quantile function. The 99th percentile can be calculated as follows:

Suppose you have a vector data of numeric values; you can calculate the 99th percentile as follows:

main.m
p = 0.99;         % set the desired percentile
pct = quantile(data, p);   % calculate the p-th percentile of data
114 chars
3 lines

Here, p is the desired percentile and data is a vector of numeric values. The quantile function returns the p-th percentile of data.

Alternatively, you can use the prctile function to achieve the same result:

main.m
pct = prctile(data, 99);   % calculate the 99th percentile of data
67 chars
2 lines

Either way, pct will be the value that represents the 99th percentile of the data.

Note that if you have NaN values in data, the percentile functions will return NaN as the output. You can remove these NaN values using the isnan function and data(~isnan(data)).

gistlibby LogSnag