我写了这段代码:。
N=10000; % number of experiments
o= 1000+randn(1,N)*sqrt(10^4); % random normal distribution with mean 1000 and variance 10^4
b=700:50:1300; % specify the number of bins (possible values of the realizations)
prob=hist(o,b)/N %create ad histogram
X = [700:50:1300] **
现在,我如何创建一个包含b和prob值的矩阵? 换句话说,我想要一个这样的矩阵:
matrix = [X(i)的值;概率关联的值为X(i)]
es:matrix = [... X(i)= 850 ...; ...... prob(X(i)= 850)..]
非常感谢你! ;)
答案 0 :(得分:1)
我想你想要计算直方图的 interval 的概率:
N = 100000; %// number of experiments
b = 700:50:1300; %// bin centers
mu = 1000; %// mean of distribution
sigma = 100; %// standard deviation of distribution
delta = (b(2)-b(1))/2; %// compute bin half-width
pb = normcdf(b+delta,mu,sigma)-normcdf(b-delta,mu,sigma); %// compute probability
检查:
o = mu + sigma*randn(1,N);
hist(o, b)
hold on
plot(b, N*pb, 'r', 'linewidth', 2)