Read ZEMAX Beam File (ZBF)

Reads a ZEMAX Beam File into Matlab, allowing presentation of physical optics simulation results.
Updated 22 Jul 2011

View License

ZEMAX is an optical simulation code ( One of its features, Physical Optics Propagation, calculates the electric fields as they travel through the simulated optical system. The results can be saved in the ZEMAX Beam File (ZBF) format. It is useful to be able to read the ZBF file into Matlab so the electric field amplitudes and phases can be plotted in Matlab for display. Multiple simulation results can be easily compared in this way.

Since this code uses mex, the user will first need to compile part of the code. I only tested this on Windows, and I believe the code will only compile using gcc. Please install MinGW ( and GNUMex ( Then, go to Matlab and type:

mex read_zbf_mex.c

This will compile the mex part of the code. To run the code, type

[ x y Ex Ey ] = read_zbf( filename )

and replace filename with a string containing the filename of the ZBF file to be read. To plot the results, issue commands like:

pcolor(x,y,real(Ex)); shading flat

to plot just the real part of the x-component of the E-field amplitude in the ZBF file.

I am grateful to Bill Jones for sending me his make_zbf C-code which I modified to make this code. I believe both of our codes are based on an example file included in ZEMAX.

Cite As

Sean Bryan (2024). Read ZEMAX Beam File (ZBF) (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired: Read a binary ZEMAX beam file (ZBF)

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

More careful definition of x and y coordinate matrices.

Changed the memory allocation on the output matrices to improve speed.