radialDistribution2​D.m

calculates radial Distribution in 2D

Vous suivez désormais cette soumission

input:
% ~~~~~~
% switchVal - operation of the finction
% initialize=0;
% sample=1;
% results=2;
% plot = 3;
%
% gR - the output struct contaning the histogram
% (shuold be created with "gR = struct;" before initialization
%
% coords - x,y coordinates of partical centers
% first row x, second row y
%
% Lx - x size of area to calculate
% Ly - y size of area to calculate
%
% NumOfBins - number of bins in the final histogram
%
% output:
% ~~~~~~~
% gR is a histogram struct contaning:
% gR.count - total number of object counted
% gR.range - x axis range for the histogram
% gR.increment - increment of x axis
% gR.saveFileName - name of saved dat file
%
% method:
% ~~~~~~~
% the RDF is calculated by binnig all pair partical distances into
% a histogram, and normalizing each bin with it's Ideal gas number of
% particals.
% when binning the pair distances, we take into acount Periodic
% Boudary Conditions (PBC)
% finaly, to ansure that when r->infinity : RDF ->1 , we
% normalize by multiplying RDF*2/(N-1) where N is the number of
% particals.
% for more information http://www2.msm.ctw.utwente.nl/sluding/TEACHING/APiE_Script_v2011.pdf
% page 48 - "Radial distribution function"

-------
|important|
-------
this function uses the functions "histogram", "distPBC2D"
"histogram" can be found here: http://www.cchem.berkeley.edu/chem195/histogram_8m.html#aedd379efd57ae78820ad8787bfab0cce
"distPBC2D" can be found here: http://www.mathworks.com/matlabcentral/fileexchange/46575-distpbc2d-m
%% example %%
example for the code above. please note that "radialDistribution2D" uses the functions "histogram" and "distPBC2D":
"histogram" can be found here: http://www.cchem.berkeley.edu/chem195/histogram_8m.html#aedd379efd57ae78820ad8787bfab0cce
"distPBC2D" can be found here: http://www.mathworks.com/matlabcentral/fileexchange/46575-distpbc2d-m

make sure these functions are in your path before you run this code.

coords = [rand(1,100); rand(1,100)]; % in this example we will calculate
% the RDF for a random sett of 100 coordinates. first row is x coordinates,
% second row is y coordinates.

Lx = 1; % board size
Ly = 1;

NumOfBins = 100; % How many bins you want in your RDF histogram. this is
% the RDF's resolution.

gR = struct; % create a struct, this is where our RDF
%(radial distribution function) will be at the end of this calculation.

% initialize gR struct
gR = radialDistribution2D(0,gR,coords,Lx,Ly,NumOfBins);

% Loop over pairs and determine the distribution of distances
gR = radialDistribution2D(1,gR,coords,Lx,Ly,NumOfBins);

% Normalize distance distribution histogram to get the RDF
gR = radialDistribution2D(2,gR,coords,Lx,Ly,NumOfBins);

% plot Result
gR = radialDistribution2D(3,gR,coords,Lx,Ly,NumOfBins);

your results are saved in "gR" struct. "gR.values" has the bins (x axis) of the RDF. "gR.histo" has the histogram (y axis) of the RDF.

Citation pour cette source

adi (2026). radialDistribution2D.m (https://fr.mathworks.com/matlabcentral/fileexchange/46576-radialdistribution2d-m), MATLAB Central File Exchange. Extrait(e) le .

Catégories

En savoir plus sur Thermal Analysis dans Help Center et MATLAB Answers

Informations générales

Compatibilité avec les versions de MATLAB

  • Compatible avec toutes les versions

Plateformes compatibles

  • Windows
  • macOS
  • Linux
Version Publié le Notes de version Action
1.1.0.0

just changed the description
added an example to the discription

1.0.0.0