我在Matlab中绘制了一个直方图(比如一些随机数的P(r) )。现在如何获得与给定的r值相对应的P( r )的值?我的意思是,在MATLAB中,我需要对应于直方图x轴上给定值的条形高度。
发布于 2013-02-02 20:55:56
从Matlab documentation for hist
[n,xout] = hist(...)返回包含频率计数和面元位置的向量n和xout。
换句话说,hist有可选的输出参数,其中包含您需要的信息。
发布于 2013-02-02 21:04:50
在我创建一些示例代码时,@Oli已经回答了这个问题:
%# Generate random data
nPoints = 100;
data = rand(N,1);
%# Calculate histogram
[nInBin, binPos] = hist(data,20);
%#Extract P() from nInBin
P = nInBin / nPoints;
%# X position to look for histgram "height" in
posToLookFor = 0.4;
%# Find closest bin
[~, closestBin] = min(abs(binPos-posToLookFor));
%#Visualize
figure();
bar(binPos,P)
hold on;
plot([posToLookFor posToLookFor], [0 P(closestBin)],'r','linewidth',3)

https://stackoverflow.com/questions/14662079
复制相似问题