View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

4.3 | 7 ratings Rate this file 25 Downloads (last 30 days) File Size: 326 KB File ID: #12092 Version: 1.6
image thumbnail




30 Aug 2006 (Updated )

Provides the attenuation and energy absorption of x-ray and gamma-ray photons in various materials.

| Watch this File

File Information

Package PhotonAttenuation provides set of functions for modeling of photons (x-ray, gamma-ray, etc.), passing through different materials. The tools are based on attenuation and energy absorption coefficients of photons in various materials. The tables of absorption coefficients were copied from NIST and embedded in the MATLAB code.
Package consist of 4 functions:
    PhotonAttenuation - the main function returning variuos physical quantaties for photons of various energies passing through different materials of different thickness
    PhotonAttenuationQ - the helper function providing bare-bones access to NIST tables hardwired into the code. Simpler version of PhotonAttenuation function with much fiewer input and output options.

    ParseChemicalFormula - converts many different styles of names used for elements, compounds and mixtures to uniform list of elements and their weight ratios.

    PhysProps - provides physical properties (like ratio of atomic number to mass or density), needed by PhotonAttenuation function, for all elements and some selected compounds.

Tables are based on "X-Ray Attenuation and Absorption for Materials of Dosimetric Interest" (XAAMDI) database (NIST 5632 report): J. Hubbell and S.M. Seltzer, "Tables of X-Ray Mass Attenuation Coefficients and Mass Energy-Absorption Coefficients 1 keV to 20 MeV for Elements Z = 1 to 92 and 48 Additional Substances of Dosimetric Interest, "National Institute of Standards and Technology report NISTIR 5632 (1995).

MAC values for elements 93 to 100 (Neptunium to Fermium) came from XCOM: Photon Cross Sections Database (NBSIR 87-3597): Those tables give photon's "total attenuation coefficients" for elements with atomic number (Z) smaller than 100. Photon energy range is from 0.001 MeV to 100 GeV.

Written by Jarek Tuszynski (SAIC), 2006
Inspired by John Schweppe Mathematica code available at

MATLAB release MATLAB 8.6 (R2015b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
24 Oct 2016 Gavin Cheung

Very useful code.
@Yi and Jarek,
The easy solution, which worked for me, is to simply initiate mu with the line
'mu = [];'
This can be inserted into line 160 just before the loop starts.

16 Jun 2016 milad najafzadeh

25 Aug 2014 William Heindl

17 Mar 2014 Yi

Yi (view profile)

Beautiful work!
Why when I run the PhotonAttenuation_Tutorial.m directly, it will display the error information as:
Error: File: PhotonAttenuation.m Line: 192 Column: 3
"mu" previously appeared to be used as a function or command, conflicting with its use here as the name of a variable.
A possible cause of this error is that you forgot to initialize the
variable, or you have initialized it implicitly using load or eval.

Error in test_YZ (line 10)
mac = PhotonAttenuation(Z, E, 'mac');

18 Sep 2013 Muthu Annamalai

23 May 2009 Erik Erikkson

01 Nov 2006 Fredrik Lidén

Excellent work Jarek!
There is still one small problem with the plot of the attenuation curves - the edges should be "vertical" but in the plot they are not. This could be improved by adding the "NIST raw data" to the vector that is to be plotted before plotting (using vertcat and sortrows). Just a suggestion...

31 Aug 2006

Text formating

06 Dec 2006

Added HTML file created by MATLAB by publishing PhotonAttenuation_Examples.m.
Fixed a bug in PhotonAttenuation.m which returned wrong order of magnitude in case of cross-sections.

13 Dec 2006

No changes to the code or description, just changing the way ZIP file is created so File Exchange website can parse it correctly.

23 Jan 2007

Minor code and spelling corrections.

27 Sep 2011 1.3

minor corrections to functions and changes to the tutorial script

08 Jul 2013 1.4

small corrections and source code cleanup

26 Aug 2014 1.5

Improve error handling

17 Mar 2016 1.6

corrected documentation: removed references to Compton Edges and replace them with absorption edges.

Contact us