Error - MATLAB expression <output of myfunc> is not numeric
이전 댓글 표시
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
Walter Roberson
2021년 2월 15일
What is showing up for class(y) after the execution of the py.throttle.test() call ?
I am not clear on which point is giving the error?
Try
y = uint64(0);
Mario Malic
2021년 2월 15일
If you call from the Command Window
y = fcn
Walter Roberson
2021년 2월 15일
No, from the command window, y comes out as uint64 .
ARUN
2021년 2월 15일
Walter Roberson
2021년 2월 15일
편집: Walter Roberson
2021년 2월 15일
Which MATLAB release are you using, and which operating system?
ARUN
2021년 2월 15일
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)
y = py.throttle.test();
class(y)
disp(y)
It works when I test on Mac or in MATLAB Online (which is Linux)
답변 (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!