MATLABでpythonのクラスの呼び出し
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
tomoki takeuchi
am 28 Jun. 2019
Beantwortet: Kojiro Saito
am 29 Jun. 2019
pythonで作成したコードのクラス内の情報を引継ぎ、中のメソッドを行いたいのですが、方法が分かりません。
class Hello():
def hello(self)
print "HelloWorld!"
このように作成し、helloのメソッドを仕様したい場合、MATLAB上にはどのように打ち込めばよいのでしょうか。
またpython上の問題があるのでしょうか。
0 Kommentare
Akzeptierte Antwort
Kojiro Saito
am 29 Jun. 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()
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu MATLAB の Python ライブラリ finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!