This Matlab function imports a raw Zemax ray database stored in ZRD file, groups the rays into distinct paths based on i) the exact same sequence of objects hit and ii) ray events (such as reflection, splitting etc.), and outputs this information in a form of graphs, human-readable variables and, most importantly, a summary table storing each path in descending total power, object sequence, total ray events and so on. It can be further processed either using Matlab's native capabilities, or exported and processed using Excel or a simple text editor.
It DOES NOT need Zemax to be installed onto your system and does not use any API to connect to it. It is a completely standalone function.
The need for this custom function came clear during one project at work as the native Zemax ray paths tool is simply not sufficient. For instance, ray grouping criteria is not clearly specified, also, the explicit sequence of objects is lost (if a ray enters the lens, is backreflected and leaves the lens through the first surface, even though 3 interactions tool place, it will be reported as a single one).
I want to note the inspiration from Michael Cheng’s Python function which helped me to write the part where the binary ray database is loaded. The original post is ‘Python Reading Writing Binary Files (ZRD, ZBF, DAT, SDF)’, available on https://community.zemax.com/code-exchange-10/python-reading-writing-binary-files-zrd-zbf-dat-sdf-3116 as of 1st November, 2024.
Although this function is shared free for use and any modification as you might see fit, I would appreciate it if you would quote me in case you are going to use it for any non-personal tasks.
Kristupas Tikuišis 2024.