Calling python function using Matlab Python Coexecution

2 Ansichten (letzte 30 Tage)
Wiz
Wiz am 9 Okt. 2024
Kommentiert: Wiz am 15 Okt. 2024
Hello everyone, I was trying to integrate my Neural Network model which is written in python to my simulink model. For this Integration I am using the Matlab python Coexecution option. After a demo Coexection (using my ML model and random inputs from matlab) it worked perfectly and predicted those random values as it should. Once I test there I created a matlab function in Simulink and tried to call this python model but somehow I am getting this error. "Attempt to extract field 'infer' from 'mxArray'. Function 'AEB_Trigger/MATLAB Function3' (#38.1529.1537), line 30, column 14: "py_model"
FYI: the inputs for the Matlab and or Python model are coming from another environment (virtual simulation), but I am quite sure that doesnt have an effect on this error. The Coexecution even works in the Matlab Command window, but having a problem when it is connected to those inputs.
Matlab Verison:2021a
Python: 3.7
Thank you very much for the time;)

Antworten (1)

Oliver Jaehrig
Oliver Jaehrig am 10 Okt. 2024
I can simply recommend to put the code into it's own function which would create a layer around it and then use coder.extrinsic to declare this particular function as extrinsic and then call this function in the MATLAB Function block.
The function itself should only get inputs and outputs with valid Simulink types. Such errors occur since Simulink cannot handle this special type since the object you get is not handled as extrinsic.
So the additional function should solve this actually.
If you need any further support, please also consider to contact our Technical Support department.
  1 Kommentar
Wiz
Wiz am 15 Okt. 2024
Thank you very much for the reply, So I recreated the code in its own function iself like attached above, but I am still getting the same error/sometimes my matlab crashes, as you have said I will probably contact Technical Support department. But again thank you a lot!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by