This section describes the various ways that MATLAB TM can be used with Lumerical's software.
Script integration
The MATLAB script integration feature allows MATLAB commands to be called directly from the Lumerical scripts. This allows you to access MATLAB's powerful analysis and visualization tools while working from within the Lumerical environment.
See MATLAB integration setup if you experience any problems using this feature.
MATLAB script integration
The Script Integration feature allows MATLAB commands to be typed directly into the Lumerical script prompt. This provides a very seamless way to take advantage of the full range of MATLAB functions.
Setup instructions and system requirements for the MATLAB script integration feature can be found in the online Knowledge Base. See the MATLAB integration setup section of the Installation Guide.The MATLAB interface functions (matlab, matlabput, matlabget) allow you to work primarily within the Lumerical script environment, but still have access to the full range of MATLAB functions when they are required. For information on supported versions of MATLAB, see the matlab script function description.
The first time one of these functions is called, it will start a MATLAB session and create a connection between the two applications. Once the connection is established, it is possible to transfer data from Lumerical to MATLAB (matlabput), transfer data from MATLAB to Lumerical (matlabget), and run MATLAB commands from the Lumerical script prompt (matlab).
For example, open usr_matlab.fsp, then run usr_matlab_optionA.lsf. A MATLAB session will be opened in the background. The MATLAB coutourf function is used to create a contour plot of the electric field intensity, as shown below. In addition to the contour plot, more advanced text formatting is possible, such as using the Greek letter Mu on the axis labels.
MATLAB script integration configuration guide
This article describes how to set up MATLAB script integration features with Lumerical products.
Notes
- Lumerical does not guarantee that all versions of our products will be compatible with all MATLAB versions on all operating systems (the number of permutations is very large!), although we have found that it works for most customers.
- Only the 64-bit version of MATLAB is supported.
- Some releases of MATLAB include newer versions of system libraries than are provided by the operating system. The new libraries are saved in a private location that only MATLAB can 'see'. This creates problems for the Matlab script integration since the Lumerical application will use the standard version of the system library while MATLAB will use its private version of the same library. This creates a conflict, which stops the script integration from working. See below for possible solutions.
- The MATLAB script integration feature requires MATLAB version 2006b to 2019a.
Lumerical to MATLAB script integration
The MATLAB script integration feature allows MATLAB script functions to be called from within Lumerical's scripts via the matlab, matlabput and matlabget script functions.
Check feature status
To check the status of the MATLAB script integration feature, go to the Help menu and select Matlab integration status.
See details below for configuration instructions for your operating system.
Windows
Step 1
The products should be able to locate the MATLAB libraries. If they are not in the system library path, you must manually specify their location.
- Open the Matlab integration status window from the Help menu.
- Use the Select button to manually locate the MATLAB system libraries.
- Restart the Product for the change to take effect.
Step 2
MATLAB must be registered as an automation server on your system before the script integration feature will work. Registration normally occurs during the MATLAB install process, but occasionally the registration fails or is lost.
In such cases, manual registration is required. Manual registration may also be required when you have multiple versions of MATLAB installed and would like to register MATLAB for the desired version, e.g. if the MATLAB license of one version is not available.
Administrator access is required for these configurations. For more information, please refer to MATLAB documentation.
- To register MATLAB, open a MATLAB session and type the following command:
!matlab /regserver
- The ! operator in MATLAB just executes the remainder of the line at the command prompt, so this is equivalent to running a command below from the Windows command prompt as Administrator,
"C:\Program Files\MATLAB\<version>\bin\win64\matlab" /regserver
- To test the registration, open Lumerical and use one of the MATLAB script integration functions. You can also test the registration within MATLAB by running;
h = actxserver('Matlab.Application') h.Execute('plot(1:10)')
- The first command starts a second background instance of MATLAB, very similar to the way our software starts a MATLAB session. The second command sends the plot command from the original MATLAB session to the new MATLAB session. You should see a simple plot window.
Linux
The following two configuration steps are often required to setup the MATLAB script integration on Linux. Occasionally, the third step will be required.
Step 1
The matlab command must be in the path, so if you type 'matlab' at the terminal, the MATLAB application will start. To do this you can either add the folder where you installed MATLAB to your PATH, or you can create a symbolic link to the matlab command in another folder that is already in the path.
$ sudo ln -s /usr/local/MATLAB/<version>/bin/matlab /usr/bin/matlab
Step 2
Your Lumerical Product must be able to locate the MATLAB libraries. If they are not in the system library path, you must manually specify their location.
- Open the Matlab integration status window from the Help menu.
- Use the Select button to manually locate the MATLAB system libraries.
- Restart the Product for the change to take effect.
Step 3
Some versions of MATLAB include newer versions of system libraries than the standard version provided by the OS. The newer libraries are saved in a private location that only MATLAB can access. This creates problems for the Matlab script integration, since your Lumerical Product will load the standard version of the system library, while MATLAB will load it's private version of the same library. This creates a conflict, which stops the script integration from working.
The easiest way to avoid this is to roll back to an older version of MATLAB.
Alternatively, you can try to configure your Lumerical Product to work with your current version of MATLAB. This requires configuring our software to use the newer system libraries provided by MATLAB, so both products load the same version of the libraries. This can be setup by creating a simple shell file that configures the library paths. Once this file is created, Lumerical can be started with a command new shell file.
(shell file for FDTD)
$ sudo cat /opt/lumerical/v232/bin/fdtd-matlab.sh (Add the following lines into the file) #!/bin/bash export LD_LIBRARY_PATH=/opt/MATLAB/<version>/sys/os/glnxa64/ /opt/lumerical/v232/bin/fdtd-solutions $@ (make the file executable) $ sudo chmod +x /opt/lumerical/v232/bin/fdtd-matlab.sh
(shell file for MODE)
$ sudo cat /opt/lumerical/v232/bin/mode-matlab.sh (Add the following lines into the file) #!/bin/bash export LD_LIBRARY_PATH=/opt/MATLAB/<version>/sys/os/glnxa64/ /opt/lumerical/v232/bin/mode-solutions $@ (make the file executable) $ sudo chmod +x /opt/lumerical/v232/bin/mode-matlab.sh
(shell file for CHARGE / HEAT / FEEM & DGTD)
$ sudo cat /opt/lumerical/v232/bin/device-matlab.sh (Add the following lines into the file) #!/bin/bash export LD_LIBRARY_PATH=/opt/MATLAB/<version>/sys/os/glnxa64/ /opt/lumerical/v232/bin/device $@ (make the file executable) $ sudo chmod +x /opt/lumerical/v232/bin/device-matlab.sh
(shell file for INTERCONNECT)
$ sudo cat /opt/lumerical/v232/bin/interconnect-matlab.sh (Add the following lines into the file) #!/bin/bash export LD_LIBRARY_PATH=/opt/MATLAB/<version>/sys/os/glnxa64/ /opt/lumerical/v232/bin/interconnect $@ (make the file executable) $ sudo chmod +x /opt/lumerical/v232/bin/interconnect-matlab.sh
Run Lumerical using the new shell file.
$ /opt/lumerical/v232/bin/interconnect-matlab.sh & $ /opt/lumerical/v232/bin/device-matlab.sh & $ /opt/lumerical/v232/bin/mode-matlab.sh & $ /opt/lumerical/v232/bin/fdtd-matlab.sh &
macOS
Step 1
Your Lumerical Product must be able to locate the MATLAB libraries. If they are not in the system library path, you must manually specify their location.
Add Lumerical installation path to your shell.
- Open Terminal
- Add the Lumerical installation path to your current shell. (i.e. All products added to path)
export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/FDTD\ Solutions.app/Contents/MacOS export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/MODE\ Solutions.app/Contents/MacOS export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/DEVICE.app/Contents/MacOS export PATH=$PATH:/Applications/Lumerical\ v232.app/Contents/Applications/INTERCONNECT.app/Contents/MacOS
- Do not close or terminate your current shell/Terminal.
- Once you close the current shell/terminal window, you will have to run the above "export" commands again on your new shell/Terminal.
- To permanently add PATH to your shell profile, checkout this article.
- Open and run Lumerical from your current shell/Terminal window.
The new PATH settings will only work when the application is launched from the Terminal window.$ fdtd-solutions & $ mode-solutions & $ device & $ interconnect &
- Open the Matlab integration status window from the Help menu from within the product.
- Use the select button to manually locate the MATLAB system libraries.
- Restart Lumerical for the change to take effect.
Step 2
It may be necessary to create the following symbolic link to the MATLAB executable.
sudo ln –s /Applications/MATLAB_<version>.app/bin/matlab /usr/bin/matlab
The exact command will depend on your MATLAB version and install directory. The above