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.
回答(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!