Good morning, everyone. I am currently modelling a prism compressor with ZEMAX and I would like to, by coupling with Matlab to extract the pulse front tilt from the compressor. As I haven't yet entered the ZOS-API, which would probably be the most direct solution to my problem but for the moment too complicated for me , I would like to manage it simply from macros. Is there a way to save a 2D variable generated under a ZEMAX macro to import it under matlab? Thank you for your valuable insight!
Translated with www.DeepL.com/Translator
Already have an account? Login
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.
You can loop through your 2D variable and use the OUTPUT, and PRINT keyword to save its values to a text file.
Additionally, you might want to use the CONVERTFILEFORMAT keyword to change the text file encoding to ANSI, which is more suited to MATLAB.
Here is an example of such a macro:
This macro should create a text file in C:\temp\ called MY_ARRAY.TXT, and should look as follow:
Remark: these numbers are integers, but they have been written with the default OUTPUT settings, which uses 4 decimals. You can change the OUTPUT format using the FORMAT keyword (I've added this for completeness).
There are then multiple ways of reading this text file in MATLAB, here is one:
Does that answer your question?
Have a great day.