Python call matlab function 'plot', The figure disappeared in few seconds.

11 ビュー (過去 30 日間)
Tianya Duan
Tianya Duan 2020 年 3 月 24 日
コメント済み: Villa Xue 2022 年 3 月 11 日
When I use python call the matlab funtion plot, the figure only exists few seconds, then it colsed automatically. Why does have this phenomenon occur? How could I change or add something? Thank you very much.
AddTset.m
function c = AddTest(a,b)
c = a + b;
figure(1)
plot(a,c,'DisplayName','test');
%pause(30);
end
pyCallMat.py
import matlab.engine
if __name__ == '__main__':
eng = matlab.engine.start_matlab()
a = eng.AddTest(1.0,2.0)
print(a)
b = eng.sqrt(4.)
eng.figure(3.0)
eng.plot(a, b, nargout=0)
print(b)
  4 件のコメント
Tianya Duan
Tianya Duan 2020 年 3 月 26 日
The question has been solved by Chinese matlab support team.
Two methods:
  1. add a line of the following command
input("Press Enter to continue...")
2. use the following answer of the website
isvalid function is more useful if you want to write a GUI.
while eng.isvalid(h):
pass
Villa Xue
Villa Xue 2022 年 3 月 11 日
Thank you a lot, It works when use: input("Press Enter to continue...") in python

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCall MATLAB from Python についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by