How to compute 99% coverage in MATLAB?

前端 未结 3 839
春和景丽
春和景丽 2021-01-17 17:05

I have a matrix in MATLAB and I need to find the 99% value for each column. In other words, the value such that 99% of the population has a larger value than it. Is there a

3条回答
  •  长发绾君心
    2021-01-17 18:07

    The simplest solution is to use the function QUANTILE as yuk suggested.

    Y = quantile(X,0.01);
    

    However, you will need the Statistics Toolbox to use the function QUANTILE. A solution that is not dependent on toolboxes can be found by noting that QUANTILE calls the function PRCTILE, which itself calls the built-in function INTERP1Q to do the primary computation. For the general case of a 2-D matrix that contains no NaN values you can compute the quantiles of each column using the following code:

    P = 0.01;       %# Your probability
    S = sort(X);    %# Sort the columns of your data X
    N = size(X,1);  %# The number of rows of X
    Y = interp1q([0 (0.5:(N-0.5))./N 1]',S([1 1:N N],:),P);  %'# Get the quantiles
    

    This should give you the same results as calling QUANTILE, without needing any toolboxes.

提交回复
热议问题