How to integrate Lumerical script and MATLAB

matlab

#1

Lumerical script provides the opportunity to integrate with MATLAB to take advantage of the powerful MATLAB tool. The MATLAB integration scripts are listed in the following table.

matlabsave: Save workspace data to a Matlab .mat file.
matlabsavelegacy: Save workspace data to a legacy Matlab .mat file format.
matlab: Execute a MATLAB command
matlabget: Get a variable from the MATLAB workspace
matlabput: Send a variable to the MATLAB workspace
matlabload: Load from MATLAB .mat file into workspace.

Three general tips for using Lumerical script & MATLAB integration:

  1. The general steps to use MATLAB in Lumerical script
    a. Use script to get the simulation result data
    b. Interpolate the result. Lumerical solvers usually use uneven mesh but MATLAB presume even mesh settings, hence directly plot from MATLAB may get skew figures.

  2. Save Lumerical workspace data to MATLAB workspace data
    Use the script command matlabsave. This data can be directly used in MATLAB with the same name. Please note that if there is dataset with the same name in MATLAB, it will be overwritten.

  3. Save data to text file
    Lumerical workspace data could be written into text files by using the script command “write”. Please note that, the “write” command writes number as string, so a space or other formats that can be recognized by third party tool are required between numbers.

a=linspace(0,2pi,9);
b=sin(a);
write(“testfile.txt”,num2str(data_to_print));


Integration with Matlab
Far field plots at fixed angle