我在Matlab中绘制了直方图(比如某些randon数的P(r))。我现在如何得到对应于给定r值的P(r)的值?我的意思是我需要在MATLAB
中直方图的x轴上对应于给定值的条形高度答案 0 :(得分:2)
来自Matlab documentation for hist
:
[n,xout] = hist(...)
会返回包含频率计数和bin位置的向量n
和xout
。
换句话说,hist
具有可选的输出参数,其中包含您需要的信息。
答案 1 :(得分:1)
请参阅@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)