フィルターのクリア

MATLAB expression '<output of py.example.test>' is not numeric

8 ビュー (過去 30 日間)
Rifshu Hussain Shaik
Rifshu Hussain Shaik 2022 年 2 月 12 日
回答済み: Sathvik 2023 年 11 月 8 日
hi, I am trying run an example python code in matlab function block in simulink but i am getting this error. it would be very helpful if you can suggest some solution.
Python(Spyder) code:
def test(a,b):
a = int()
b = int()
result = a + b
return result
MATLAB FUNCTION code:
function result = python(a, b)
result = 0
coder.extrinsic('py.example.test')
result = py.example.test(a, b) # error at this line(MATLAB expression '<output of py.example.test>' is not numeric)
end
  1 件のコメント
Alireza
Alireza 2022 年 8 月 17 日
I have same problem. Any update?

サインインしてコメントする。

回答 (1 件)

Sathvik
Sathvik 2023 年 11 月 8 日
Hi Rifshu,
I understand that you’re trying to resolve the error while calling Python Functionality from MATLAB.
The variables ‘a’ and ‘b’ in the python code are initialized as ‘int’ variables. The output of py.example.test, when called from MATLAB, returns a ‘py.int’ type. You can resolve the error by using the ‘double’ function in the ‘MATLAB FUNCTION code’.
result = double(py.example.test(a,b));
Please refer to the following MATLAB Answers and Documentation links to gain more insight on running Python code in MATLAB and Simulink:
Hope this helps!

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by