Compiling Simulink model to Python library successful, but calling it throws error

5 views (last 30 days)
For my project I want to use complex Simulink models but call them and import results to Python package. I used very simple example to check this opportunity. The Simulink model is very trivial:
After this I use the following script:
function res = make_test()
res = sim('./untitled.slx');
end
And compile it to Python code using Matlab Library Compiler, including my *slx and *slxc files. Building is successful, I can install my library with:
python setup.py install
After I import it in python and trying to call it:
import make_test
test = make_test.initialize()
xOut = test.make_test()
Unfortunately it throws an error:
Dot indexing is not supported for variables of this type.
Is there any idea about it? Is there any other way to compile Simulink model to python library? matlab.engine is good but you cannot use it on the computer without Matlab.

Answers (1)

arushi
arushi on 22 Nov 2023
Hi Alexey,
I understand that the error you are encountering when attempting to call the compiled MATLAB function from Python is likely due to the way the result is being returned from the MATLAB function. When using the MATLAB Compiler SDK to create a Python package from a MATLAB function, it's important to ensure that the output from the MATLAB function is compatible with Python.
One possible reason can be that the sim function in MATLAB/Simulink returns a Simulink.SimulationOutput object, which is not directly compatible with Python. To address this issue, you can modify the MATLAB function to return the specific results you need in a compatible format, such as a numerical array or a structure.
You may consider reviewing the documentation for MATLAB Compiler SDK and ensuring that the output from the MATLAB function is compatible with Python-
Hope this helps.
Thank you

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!