Filter löschen
Filter löschen

Integrate kernel probability distribution function

3 Ansichten (letzte 30 Tage)
Alessandro Ruda
Alessandro Ruda am 5 Aug. 2020
Beantwortet: Jeff Miller am 5 Aug. 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;
[f3,y6i] = ksdensity(y6);
xlabel('\theta (deg)');
ylabel('P(\theta) (deg^{-1})');
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,

Antworten (2)

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

Jeff Miller
Jeff Miller am 5 Aug. 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.




Community Treasure Hunt

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

Start Hunting!

Translated by