Python script within my MATLAB Function
Afficher commentaires plus anciens
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.
Réponses (0)
Catégories
En savoir plus sur Call Python from MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!