Effacer les filtres
Effacer les filtres

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

7 vues (au cours des 30 derniers jours)
tomoki takeuchi
tomoki takeuchi le 28 Juin 2019
pythonで作成したコードのクラス内の情報を引継ぎ、中のメソッドを行いたいのですが、方法が分かりません。
class Hello():
def hello(self)
print "HelloWorld!"
このように作成し、helloのメソッドを仕様したい場合、MATLAB上にはどのように打ち込めばよいのでしょうか。
またpython上の問題があるのでしょうか。

Réponse acceptée

Kojiro Saito
Kojiro Saito le 29 Juin 2019
以下のような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を呼び出す際の制約はこちらのドキュメントに記載があるので参考になると思います。

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB の Python ライブラリ dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!