简体   繁体   中英

How can I create a probability density function in Matlab?

I have a table with two sets of values.

And I want to create equally sized bins of x, count the number of values of y in each bin and then plot it.

How can I do it?

Data

x    y
0   0.0023243872
815.54065   0.0021484715
1111.9492   0.0023388069
1378.9236   0.0021542402
1631.0813   0.0021254013
1927.4899   0.0023618778
2194.3323   0.0021484711
2223.8984   0.0023157364
2446.6221   0.0022868966
2490.8728   0.0023388073
2743.0305   0.0024801167
3009.7410   0.0021917303
3262.1626   0.0022955481
3306.2815   0.0021052146
3335.8479   0.0023330392
3558.5713   0.0024772326
3602.6660   0.0023474589
3825.1497   0.0022292205
4121.6904   0.0021023308
4374.1118   0.0024916520
4447.7969   0.0023935998
4640.5586   0.0022522912
4714.5371   0.0023705289
4937.0991   0.0022263369
5233.6396   0.0021773111
5262.8101   0.0024656970
5455.9673   0.0024339736
5559.7461   0.0024455092
5752.5078   0.0021167498
5752.5078   0.0027021724
5826.4863   0.0023936001
6019.4819   0.0027021721
6048.7842   0.0021686594
6271.3760   0.0024368572
6345.5889   0.0022321043
6567.9165   0.0021167498
6612.3291   0.0022205692
6835.0225   0.0027165920
7131.4312   0.0027483148
7160.6016   0.0023849490
7427.3418   0.0020042793
7457.5381   0.0022032652
7650.2212   0.0021109823
7724.2002   0.0023301556
7724.2783   0.0022090334
7724.2783   0.0021801949
7947.1040   0.0028059918
7947.1040   0.0027425468
8242.3545   0.0019927442
8243.3809   0.0029588358
8465.4980   0.0024455097
8465.4980   0.0022032652
8510.5107   0.0029213454
8539.2910   0.0022148010
8539.2910   0.0020734922
8762.1709   0.0021686594
8762.1709   0.0026070056
8762.7764   0.0028232955
8805.9531   0.0020042795
8806.0313   0.0020590730

I don't think the y matters. You just want to count the number of references to the x, which represent the y. You can use the hist(x, bins) method where x is the vector of data, your x, and bins is the number of bins you would like to put them in. See http://www.mathworks.com/help/matlab/ref/hist.html

I am not sure to understand how we need y. Is this what you are looking for ?

N = 100 ;
x = rand(N, 1) ;
M = hist(x) ;
plot(M) ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM