Filter löschen
Filter löschen

using python code in Matlab function block of Simulink

6 Ansichten (letzte 30 Tage)
Leila Shams Ashkezari
Leila Shams Ashkezari am 21 Jun. 2022
Beantwortet: arushi am 22 Aug. 2024 um 4:27
hi,
I defined a simple control algorithm in Python which returns 3 outputs. I want to call this function in a matlab function block and give its outputs to the outputs of this block in simulink. but the data that it receives from python are either a tuple or a list and after converting them to a cell, it is not possible to convert them in double, because in simulink it shows an error that cell2mat(), cellfun() or double() are not supported in its code generation.
considering that, i would be grateful if any of you can help me how i can convert python list or tuple to a double value in matlab function block.

Antworten (1)

arushi
arushi am 22 Aug. 2024 um 4:27
Hi Leila Shams Ashkezari
To use ‘cell2mat()’ and other functions inside the ‘MATLAB function’ block, you can utilize the 'coder.extrinsic' function within the 'MATLAB function' block.
This function instructs the code generator to avoid generating the body of the extrinsic function. Instead, it enables the MATLAB engine to execute the function call.
Here's an example of using 'coder.extrinsic' with the 'cell2mat' function to convert a cell to the desired format:
coder.extrinsic('cell2mat');
cell2mat(variableName)
For more detailed information, you can consult the following documentation:
Hope this helps.

Kategorien

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

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by