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 function in MATLAB for this?
我在MATLAB中有一个矩阵我需要找到每一列99%的值。也就是说,99%的人口的价值大于它。MATLAB中有这样的函数吗?
3 个解决方案
#1
11
Use QUANTILE function.
使用分位数函数。
Y = quantile(X,P);
where X is a matrix and P is scalar or vector of probabilities. For example, if P=0.01, the Y will be vector of values for each columns, so that 99% of column values are larger.
其中X是一个矩阵,P是概率的标量或向量。例如,如果P=0.01, Y将是每个列的值的向量,所以99%的列值都更大。
#2
10
The simplest solution is to use the function QUANTILE as yuk suggested.
最简单的解决方案是按照yuk的建议使用函数分位数。
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:
但是,您将需要统计工具箱来使用函数分位数。可以通过注意分位数调用函数PRCTILE来找到不依赖于工具箱的解决方案,PRCTILE本身调用内置函数INTERP1Q来进行主计算。对于不包含NaN值的二维矩阵的一般情况,可以使用以下代码计算每个列的分位数:
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.
这将给您与调用QUANTILE相同的结果,而不需要任何工具箱。
#3
2
If you do not have the Statistics Toolbox, there is always
如果您没有统计工具箱,则始终存在
y=sort(x);
y(floor(length(y)*0.99))
or
或
y(floor(length(y)*0.01))
depending on what you meant.
这取决于你的意思。
#1
11
Use QUANTILE function.
使用分位数函数。
Y = quantile(X,P);
where X is a matrix and P is scalar or vector of probabilities. For example, if P=0.01, the Y will be vector of values for each columns, so that 99% of column values are larger.
其中X是一个矩阵,P是概率的标量或向量。例如,如果P=0.01, Y将是每个列的值的向量,所以99%的列值都更大。
#2
10
The simplest solution is to use the function QUANTILE as yuk suggested.
最简单的解决方案是按照yuk的建议使用函数分位数。
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:
但是,您将需要统计工具箱来使用函数分位数。可以通过注意分位数调用函数PRCTILE来找到不依赖于工具箱的解决方案,PRCTILE本身调用内置函数INTERP1Q来进行主计算。对于不包含NaN值的二维矩阵的一般情况,可以使用以下代码计算每个列的分位数:
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.
这将给您与调用QUANTILE相同的结果,而不需要任何工具箱。
#3
2
If you do not have the Statistics Toolbox, there is always
如果您没有统计工具箱,则始终存在
y=sort(x);
y(floor(length(y)*0.99))
or
或
y(floor(length(y)*0.01))
depending on what you meant.
这取决于你的意思。