Error - MATLAB expression <output of myfunc> is not numeric

5 visualizaciones (últimos 30 días)
ARUN
ARUN el 15 de Feb. de 2021
Comentada: Walter Roberson el 15 de Feb. de 2021
I am trying to pass a value from the python code to the Matlab function in simulink and I am getting the following error:
Error - MATLAB expression <output of myfunc> is not numeric.
Matlab function -
function y = fcn
y = 0;
coder.extrinsic('py.throttle.test')
y = py.throttle.test();
end
Python code(throttle.py)
def test():
throttle = 5
return throttle
any idea how this could be solved?
  7 comentarios
ARUN
ARUN el 15 de Feb. de 2021
I am using MATLAB R2020b and Windows 10
Walter Roberson
Walter Roberson el 15 de Feb. de 2021
filename = 'throttle.py';
[fid, msg] = fopen(filename, 'wt');
if fid < 0
error('Failed to open file "%s" because "%s"', filename, msg);
end
fprintf(fid, 'def test():\n');
fprintf(fid, ' throttle = 5\n');
fprintf(fid, ' return throttle\n');
fclose(fid)
ans = 0
y = py.throttle.test();
class(y)
ans = 'int64'
disp(y)
5
It works when I test on Mac or in MATLAB Online (which is Linux)

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by