How can I execute ".m file" in Python 3.8?

조회 수: 7 (최근 30일)
관웅 윤
관웅 윤 2021년 9월 8일
답변: 관웅 윤 2021년 9월 13일
I am trying to execute "sim_profiles.m" which has several dependencies such as Parallel computing toolbox(parfor), LIONSIMBA(Simulation library written as Matlab). I referenced a document, "Get Started with MATLAB Engine API for Python". This is what I have tried:
import numpy as np
import matlab.engine
eng = matlab.engine.start_matlab()
fitness, measured_data = eng.sim_profiles(1, 1, arr_data, 100)
print(fitness, measured_data)
It printed the followed exception
MatlabExecutionError:
File C:\Users\user\Desktop\LIONSIMBA\LIONSIMBA-master\LIONSIMBA-master\battery_model_files\simulator_tools\differentialInitialConditions.m, line 33, in differentialInitialConditions
File C:\Users\user\Desktop\LIONSIMBA\LIONSIMBA-master\LIONSIMBA-master\startSimulation.m, line 226, in mainCore
File C:\Users\user\Desktop\LIONSIMBA\LIONSIMBA-master\LIONSIMBA-master\startSimulation.m, line 112, in startSimulation
File C:\Users\user\Desktop\강화학습\pytorch-soft-actor-critic-SAC_V\pytorch-soft-actor-critic-SAC_V\sim_profiles.m, line 36, in sim_profiles
Integers can only be combined with integers of the same class, or scalar doubles.
I already tested "sim_profiles.m" code in MATLAB and it works without any error.
  댓글 수: 2
관웅 윤
관웅 윤 2021년 9월 8일
I solved this problem with this link. I guess Matlab did not apply implicit casting to variables from Python. The following code works perfectly.
fitness, measured_data = eng.sim_profiles(1, 1, matlab.double(arr_data), matlab.double([100]))
Yongjian Feng
Yongjian Feng 2021년 9월 12일
Put your comment above as an anwer to this question, and then accept it. Then others encounting similar question can find the answer.

댓글을 달려면 로그인하십시오.

채택된 답변

관웅 윤
관웅 윤 2021년 9월 13일
I solved this problem with this link. I guess Matlab did not apply implicit casting to variables from Python. The following code works perfectly.
fitness, measured_data = eng.sim_profiles(1, 1, matlab.double(arr_data), matlab.double([100]))

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by