Integrate kernel probability distribution function

6 visualizaciones (últimos 30 días)
Alessandro Ruda
Alessandro Ruda el 5 de Ag. de 2020
Respondida: Jeff Miller el 5 de Ag. de 2020
Dear MatLab comunity,
I have a distribution of dihedral angles over a number of frames from a simulation. (attached is the data file)
M2OH6 = load('OH6p.txt');
y6 = M2OH6(:,2);
nbins = 100;
rng('default')
[f3,y6i] = ksdensity(y6);
plot(y6i,f3,'Color','r','Linewidth',1)
xlabel('\theta (deg)');
ylabel('P(\theta) (deg^{-1})');
xticks(-360:60:360);
yticks(0:0.01:0.045);
axis([-360 360 0 0.045]);
pbaspect([1 1 1]);
So I need to know what is the percentage of the states falling in the range between let's say 0:120 degrees (theta), 120:180 degrees and 180:-120.
In such case I was thinking that maybe I should integrate the kernel density function in such ranges but I'm not sure how to do it and obviously I'm a very beginner in MatLab.
Is there anybody who could suggest me a way?
Thanks in advance,
Alex

Respuestas (2)

Peng Li
Peng Li el 5 de Ag. de 2020
trapz is a function that deals with numerical integration. Check the above link for details.

Jeff Miller
Jeff Miller el 5 de Ag. de 2020
If you just want to know the percentages in various ranges, it seems easier to tabulate the scores directly than to mess about with ksdensity. What about just something like:
M2OH6 = load('OH6p.txt');
y6 = M2OH6(:,2);
binEdges = [-180 -120 0 120 180]; % set the boundaries to isolate the bin ranges you are interested in
counts = histcounts(y6,binEdges); % count the number of scores in each range
pcts = counts / length(y6)*100 % convert to percentages
the first pcts value will be the % between -180 and -120, the second between -120 and 0, etc. Obviously you can set the bin edges whereever you want them.

Categorías

Más información sobre Numerical Integration and Differentiation en Help Center y File Exchange.

Productos


Versión

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by