Python script within my MATLAB Function

Hello, I made a simple python function that takes a list of numbers, increments all elements of the list and return the new list.
I'm trying call this function in simulink with a MATLAB Function block. It works when I give a single constant to the MATLAB Function but when I give a 1-N vector to the MATLAB Function, I got this error : Conversion of MATLAB 'double' to Python is only supported for 1-N vectors.
So my question is : how can I enter a vector in a MATLAB Function with python code inside ?
This is my python script
def add(array):
for i in range(len(array)):
array[i] += 1
return array
This the matlab code for the MATLAB Function
function y = fcn(u)
y = 0; % Has to be preassigned, otherwise Simulink throws an error
coder.extrinsic('py.test.add') % Python functions have to be run extrinsically, meaning no C code generated
y = py.test.add(u);
end
This is de model is Simulink
Here is the error I got
Thank you for your help.

2 个评论

NB : the python file name is test.py and has to be in the same directory of the matlab project
And I'm using python 3.8 and MATLAB R2016b

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by