Transforming datasets as structures to Matlab


I am using Lumerical FDTD Solutions for my research project. I wonder if it is possible to export datasets from monitors in gridded format, so that no reshaping is needed in Matlab. I obtained the datasets via the command getresult in Lumerical prompt, and I export them to a Matlab file with the command matlabsave. However, the electromagnetic field data is exported as a column vector into Matlab instead of a matrix and I need to reshape them before processing them.

1 Like

Hi, when you matlabsave the packaged E fields, they will be indeed exported in struct format and the E field has a form of a column/vector.

You could remove the E filed matrix from the packaged data before using matlabsave to save the data as a simple matrix. The drawback is that you will have to save the frequency and coordinates separately, but it is probably easier than reshaping the vector into a matrix.

An example:
I have a simple simulation with field monitor:

This script will get the field data to workspace and separates E field data into a matrix:


Resulting in the packaged data with x,y,z coordinates and frequency information. The Eonly matrix then contains the complex Ex,Ey,Ez values only, but it is a matrix:

In Matlab:

Additionally, if you simply want to plot the data in Matlab, you can simply use the “export to matlab” button in the visualizer:


For completeness, I would also mention that matrices and vectors can be moved between Matlab and Lumerical via API instead of matlabsave as described here:

Packaged data can be transferred only via *.mat file.


Thanks for your detailed response I will definitely try it.


If I want to reshape the vector, what would be the order? is it x, y and z?


That is correct. The E matrix dimensions will be x,y,z,f.