How to save a 2D array variable outside ZEMAX macro

  • 9 September 2019
  • 4 replies
  • 238 views

Badge
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

4 replies

Userlevel 1

Hi Luc,



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.


Badge
That answers my question perfectly! Thank you very much for your help. In fact, I found OUTPUT all on my own in the meanwhile, but your example will help me optimize my program for matlab. Again, thank you very much. Have a good day too.
Userlevel 1
Also, I forgot but in case, here's the macro attached so that in the future you won't have to copy my screenshot manually.
Badge
Thanks !

Reply