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 件のコメント

William Pale
William Pale 2021 年 3 月 4 日
NB : the python file name is test.py and has to be in the same directory of the matlab project
William Pale
William Pale 2021 年 3 月 4 日
And I'm using python 3.8 and MATLAB R2016b

サインインしてコメントする。

回答 (0 件)

カテゴリ

質問済み:

2021 年 3 月 4 日

コメント済み:

2021 年 3 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by