matlabload: can not open file *.mat for reading

madRaccoon Member Posts: 3
First Comment
edited June 3 in Optics


I am trying to import polygon verticies from a matlab file. The file contains matlab variables, which are arrays of floats and integers.

The "matlabload" function doesn't comply, and returns this error :

> matlabload("my_file.mat");

Error: prompt line 2: in matlabload: can not open file my_file.mat for reading

To debug, I created a quick test file in matlab:

>> aa=1
>> bb="bb"
>> cc=[1,2,3]
>> save("test.mat", "aa","bb","cc")

I then tried to open it in Lumerical, and failed :

> matlabload("test.mat");

Error: prompt line 1: matlabload could not import matlab variable bbinto workspace: MATLAB variable is an unsupported variable type

I tried to open both files in fdtd-solutions and mode-solutions, I still have the same problem.

Has anyone ever encountered this problem? Could someone share clues on how to avoid or solve this issue ?

Many thanks,


Best Answer

  • trob
    trob Member, Employee Posts: 1
    Ansys Employee First Answer First Comment
    Answer ✓

    Hello Xavier,

    I sorry for the delayed response. I know we don't support all MATLAB data types in Lumerical; unfortunately it seems strings seem to present a problem when saved to .mat file from MATLAB. The variable bb is causing the problem because it is a string. I tested this and the numeric variables both work. This is likely a bug because it used to be possible to get strings from MATLAB.

    The other direction seems to be behave better, that is saving strings or numerical data from Lumerical, using matlabsave("f_name"), can be loaded into Lumerical or MATLAB.

    In your case transferring numerical arrays such as vertices should work without issue, just avoid passing string variables this way.

    Best Regards,


  • madRaccoon
    madRaccoon Member Posts: 3
    First Comment

    Thank you for your response, trob.

    The data I am trying to transfer was in reality just a bunch of arrays and floats (to then calculate the verticies to a polygon) Yet the issue still persisted.

    The efficient and extremely unelegant method I found was simply to:

    1. Print my variables into a text file from matlab (or python)
    2. Copy-paste their values into a lumerical script file (.lsf)
    3. Save these arrays as lumerical datasets (.ldf) using savedata("f_name.ldf")
    4. Use loaddata("f_name.ldf") to import the datasets whenever I needed them

    Again, extremely unelegant, yet it works and I got to move on with my work.

    Best of luck out there to anyone who finds this useful. It's best to check if there is a new update that has solved this issue.

  • Xuanlun
    Xuanlun Member Posts: 1
    First Comment

    Maybe the script "matlabload" in Ansys does not support ".mat" data that is lower than v7. When I save my data in MATLAB by changing "-v7" (default) to "-v7.3", ansys script can load the mat data well. You guys can try this.