Python code in MATLAB
1 回表示 (過去 30 日間)
古いコメントを表示
File name HBMtrail.py
import jos3
import pandas as pd
import numpy as np
class HBM():
def __init__(self,To = np.ones(60), RH = np.ones(60), Va = np.ones(60), no_steps=60):
self._no_steps = no_steps
self._To = To
self._RH = RH
self._Va = Va
def joshbm(self ):
model = jos3.JOS3(height = 1.71, weight = 74, age = 23)
no_steps = self._no_steps
To = self._To
RH = self._RH
Va = self._Va
for i in range(no_steps):
model.To = To[i]
model.RH = RH[i]
model.Va = Va[i]
model.simulate(1)
res = model.dict_results()
df = pd.DataFrame(res)
valid_res = df[df.columns[4:21]]
final_res = valid_res.tail(1)
final_res = final_res.values.tolist()
final_res = final_res[0]
return final_res
The above is the python code and I want this function to be exected in MATLAB
model = py.HBMtrail.HBM(To = [20,21,22],RH = [40,50,60],Va = [0.1,0.2,0.3], no_steps = 3).joshbm()
when I tried the above code in MATLAB I was getting the follwing error
Python Error: TypeError: __init__() takes from 1 to 5 positional arguments but 9 were given
But when I run the same code in python I code runs perfectly fine what should I do?
0 件のコメント
回答 (1 件)
Yongjian Feng
2021 年 7 月 1 日
You want to use python list as input arguments. Try
model = py.HBMtrail.HBM(To = {20,21,22},RH = {40,50,60},Va = {0.1,0.2,0.3}, no_steps = 3).joshbm()
0 件のコメント
参考
カテゴリ
Help Center および 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!