Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在matlab中绘制概率密度函数?_Matlab_Distribution_Uniform - Fatal编程技术网

如何在matlab中绘制概率密度函数?

如何在matlab中绘制概率密度函数?,matlab,distribution,uniform,Matlab,Distribution,Uniform,我需要画一个均匀分布矩阵的概率密度函数 U = rand (1,1000) 但是我不能用密度函数。我试过这个: term = 1000; U = rand (1,term); x=0:0.001:1; for j = 2:term; u_height(j) = u_height(j-1)+((abs(x(j)-U(j))<0.01/2)/0.01)/term; n_height(j) = n_height(j-1)+((abs(x(j)-N(j))<0.01/2)/

我需要画一个均匀分布矩阵的概率密度函数

U = rand (1,1000)
但是我不能用密度函数。我试过这个:

term = 1000;
U = rand (1,term);
x=0:0.001:1;
for j = 2:term;
    u_height(j) = u_height(j-1)+((abs(x(j)-U(j))<0.01/2)/0.01)/term;
    n_height(j) = n_height(j-1)+((abs(x(j)-N(j))<0.01/2)/0.01)/term;
end
term=1000;
U=兰特(1,期限);
x=0:0.001:1;
对于j=2:术语;

u_height(j)=u_height(j-1)+(abs(x(j)-u(j))函数
ksdensity
应该可以正常工作。您需要指定PDF的范围是有限的,并使用一个box内核

u = rand(10000,1);

ksdensity(u, 'Support', [0 1], 'kernel', 'box');
此外,您还可以使用
histc

u = rand(10000,1);
bins = 0:.05:1;
counts = hist(u, bins);
p = counts ./ trapz(bins, counts);

plot(bins, p);

你到底想做什么?
plot(U/sum(U))有什么问题
?你考虑过直方图吗?请看
hist
hist
@Junuxx,这行不通,请看这个:@slayton:我明白你的意思,谢谢你的更正。不过,OPs方法似乎很复杂。@Junuxx,是的,这个方法没有任何意义。你为什么推荐
box
?(与保留默认设置或使用
epanechnikov
相反)@DennisJaheruddin实际上两者都很好,但在对各种选项进行了修改之后,我觉得box内核生成的估计值更接近于均匀分布。虽然这接近于我所寻找的值,但它不够精确,即使是10000大小的向量。@user2064077记住这是对un的估计值精度将取决于数据集的大小和质量。