Hello Daniel,
Here is a code snippet you could use to to change the surface number (in this case to surface 3) and get the surface sag data:
Sag = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.SurfaceSag);
Sag_Settings = Sag.GetSettings();
Sag_Settings.Surface.SetSurfaceNumber(3);
Sag.ApplyAndWaitForCompletion();
SagResults = Sag.GetResults();
SagResults.GetTextFile(System.String.Concat(TheApplication.SamplesDir, '\API\Matlab\Sag example.txt'));
Note this will save a text file in samples directory, but it can be changed as needed.
Best,
Berta
Hi Berta,thanks or sharing.
Is there a way tp save it as a matrix to my Matlab workspace?
Also, how do I extarct the X,Y grid?. so eventually I would like to save a point cloud [X Y Z] data
Thanks
Hi Daniel,
Thanks for getting back to us!
You may retrieve the matrix results by using the following line:
matrixData = SagResults.DataGrids(1).Values.double;
In general, analysis window data is split into multiple categories within the IAR_ Interface. A matrix of data (as in case of the Sag analysis) will typically be provided as a DataGrid while a 2 column list of data (such as that given by a Cross Section plot) will be provided by a DataSeries.
You may find more information about pulling the data and plotting it directly in MATLAB in this forum thread:
How do I output the image of an analysis in ZOS-API? · MyZemax
Further details about all the different analysis types and their available output formats are given in this knowledgebase article:
Generating a list of output data types for each analysis in the ZOS-API
I hope this helps, but if you have any further questions, please do not hesitate to ask!
Best,
Csilla
HI Csilla,
How do I retrieve the the text file info directly to Matlab workspace
an example
Surface Sag Map
Surface 7: S1
Units are Millimeters.
Pupil grid size: 257 by 257
Center point is: 129, 129
Width = 46.97, Decenter x = 0, y = 0 Millimeters.
Point spacing = 0.1834733 Millimeters.
Hi Daniel,
These extra information are stored in the MetaData and HeaderData properties. You may read more about how to pull these lines to MATLAB in this forum thread:
How can I pull Peak Irradiance or Total Hits from the Detector Viewer analysis in the API? · MyZemax
If you would like to read back the results from the saved text file to MATLAB, then you can use fscan or a similar MATLAB command to pull the data into native variables in MATLAB. You can use the following forum post to get you started:
Extract Data from text File - MATLAB Answers - MATLAB Central (mathworks.com)
If your end goal is to use the measured surface sag info to create a new Grid Sag surface, then these knowledgebase articles will show you the steps how to do it:
How to use the Grid Sag surface type · MyZemax
How to write a Grid Sag DAT file programmatically · MyZemax
How to convert any sequential surface to a Grid Sag Surface using the ZOS-API · MyZemax
If you have any further questions, please let us know and we will be happy to help!
Best,
Csilla