# Transforming datasets as structures to Matlab

#1

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
#2

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:

E=getresult("monitor","E");
Eonly=pinch(E.E);
matlabsave("testmatlab");


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:

3 Likes
#3

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:
https://kb.lumerical.com/en/index.html?ref_scripts_interoperability.html

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

2 Likes
#4

Thanks for your detailed response I will definitely try it.

#5

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

#6

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