Calling python function that calls another file from Matlab

Hello,
My python file all_functions.py has a function of
import vib_calc as vib
def calc_cac(a):
formula_involving vib.anotherfunc(a[1])
return press
This I can call from matlab as py.all_functions.calc_cac(input). The problem is, calc_cac(a) also uses a command "import vib_calc as vib" which is basically using another vib_calc.py file as import as it has another loads of functions inside it, that are required for calc_cac(input).
Hence my former call from matlab of
py.all_functions.calc_cac(input)
throws an error of
Error using vib_calc>supportplates
Python Error: TypeError: 'float' object cannot be interpreted as an integer.
I am guessing this is because I have not informed matlab about the whereabouts of vib_calc file, but I am not sure how can I do this?

 採用された回答

Daniele Sportillo
Daniele Sportillo 2022 年 12 月 15 日
編集済み: Daniele Sportillo 2022 年 12 月 15 日

0 投票

Hi,
the problem may be related to the type of the "input" variable, which is by default float.
Try calling your python function with the argument cast to integer:
py.all_functions.calc_cac(int16(input))

3 件のコメント

Atul
Atul 2022 年 12 月 15 日
The input is actually of the type,
input =
27.0000 21.0000 3.0000 384.0000 3.0000 3.0000 4.0000 1.0350 0.0310 0.1850
where the first 7 indices should be integers and the rest as floats.
Seems I cannot get mixed data type vector after doing
inp_new = [int16(input(1:7)), double(input(8:10))]
Daniele Sportillo
Daniele Sportillo 2022 年 12 月 15 日
Right, this should work:
inp_new = py.list(int16(input(1:7))); % Create a list with the first 7 elements cast to int
inp_new.extend(input(8:10)); % Append the last 3 elements as double
py.all_functions.calc_cac(inp_new)
Atul
Atul 2022 年 12 月 15 日
It did. Thanks.

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

その他の回答 (0 件)

カテゴリ

製品

質問済み:

2022 年 12 月 15 日

コメント済み:

2022 年 12 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by