필터 지우기
필터 지우기

Python code in MATLAB

조회 수: 2 (최근 30일)
K G V Kalyan Sreenivas Kumar
K G V Kalyan Sreenivas Kumar 2021년 5월 11일
답변: Yongjian Feng 2021년 7월 1일
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?

답변 (1개)

Yongjian Feng
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()

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by