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개)

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

질문:

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