Skip to main content

How to save a 2D array variable outside ZEMAX macro

  • September 9, 2019
  • 4 replies
  • 312 views

Forum|alt.badge.img
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
Did this topic help you find an answer to your question?

4 replies

David Nguyen
Zemax Staff
  • Zemax Staff
  • 23 replies
  • September 11, 2019

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.


Forum|alt.badge.img
  • Author
  • Single Emitter
  • 2 replies
  • September 11, 2019
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.

David Nguyen
Zemax Staff
  • Zemax Staff
  • 23 replies
  • September 12, 2019
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.

Forum|alt.badge.img
  • Author
  • Single Emitter
  • 2 replies
  • September 12, 2019
Thanks !

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings