如何查找值是否位于直方图的边界之间?

How to find if a value lies in between bounds of a histogram?

我有一组经验数据(假设 x=normrnd(10,3,1000,1);),其累积分布函数如下:

我还有一组数据x1=[11,11.1,10.1]。如果 x1 的值来自 x 分布,我想求得这些值的概率。如果它是一个连续的已知函数,我可以准确地评估它,但我想根据我拥有的数据来做。有什么想法吗?

我会用手找到 x 轴上的值并追踪到直线并穿过 F(x) 轴(见图 1)。

编辑:

size(x1)
10,0000

所以我现在找到了如何获取绘制 F(x)

的数据
handles=cdfplot(X);
xdata=get(handles,'XData');
ydata=get(handles,'YData');

我认为现在是在 xdata 的间隔中找到 x 的位置,然后在 ydata 中找到位置的情况。

例如

for i=1:length(x)
    for j=1:length(xdata)
        if x(i,1)<=xdata(jj,1)
            X(i)=xdata(jj,1);
        end
    end
end
Y=ydata(X);

Is this the most elegant way?

使用 bsxfun 有一种更优雅的方法可以做到这一点。此外,您可以使用 ecdf 而不是 cdfplot 来计算经验累积分布函数(除非您确实需要该图):

x = normrnd(10,3,1000,1);
[f_data, x_data] = ecdf(x);
x1 = [11, 11.1, 10.1];

idx = sum(bsxfun(@le, x_data(:)', x1(:)), 2);
y1 = f_data(idx);