using python code in Matlab function block of Simulink

6 次查看(过去 30 天)
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.

回答(1 个)

arushi
arushi 2024-8-22
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.

类别

Help CenterFile Exchange 中查找有关 Programmatic Model Editing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by