MATLABでpythonのクラスの呼び出し

조회 수: 4 (최근 30일)
tomoki takeuchi
tomoki takeuchi 2019년 6월 28일
답변: Kojiro Saito 2019년 6월 29일
pythonで作成したコードのクラス内の情報を引継ぎ、中のメソッドを行いたいのですが、方法が分かりません。
class Hello():
def hello(self)
print "HelloWorld!"
このように作成し、helloのメソッドを仕様したい場合、MATLAB上にはどのように打ち込めばよいのでしょうか。
またpython上の問題があるのでしょうか。

채택된 답변

Kojiro Saito
Kojiro Saito 2019년 6월 29일
以下のようなPythonファイルをMATLABのカレントディレクトリに置いておき、
helloClass.py
class Hello:
def hello(self):
print "HelloWorld!"
# print('HelloWorld!') # Python 3.x
MATLABから以下のように呼ぶことで使用できます。
myHelloClass = py.importlib.import_module('helloClass');
myHello = myHelloClass.Hello();
myHello.hello()
MATLABからPythonを呼び出す際の制約はこちらのドキュメントに記載があるので参考になると思います。

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB の Python ライブラリ에 대해 자세히 알아보기

태그

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!