MATLAB in Python problems

10 ビュー (過去 30 日間)
Konoha Hokage
Konoha Hokage 2021 年 1 月 14 日
編集済み: Hitesh 2025 年 1 月 31 日
Recently I came to learn python to use it in MATLAB from a learn python tutorial. The figure turned off automatically after it showed up. Can anyone tell me whats the probable reason for this?
I wrote a simple code through cmd in windows:
import matlab.engine
eng=matlab.engine.start_matlab()
eng.plot(1.0,2.0,nargout=0)
It works well.
But I wrote exactly the same code in pycharm, the figure turned off automatically after it showed up.
  1 件のコメント
Dhruv
Dhruv 2025 年 1 月 23 日
Hi Konoha, I am able to generate the plot in R2024b

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

回答 (1 件)

Hitesh
Hitesh 2025 年 1 月 31 日
編集済み: Hitesh 2025 年 1 月 31 日
Hi Konoha,
The issue you're experiencing is related to how PyCharm handles the execution of scripts compared to running them directly from the command line. When you run a script in PyCharm, it might execute and then immediately close the window once the script finishes. This is causing the figure window to close automatically.
To prevent the figure from closing immediately, you need to add a pause or a blocking function to keep the script running until you manually close the figure.
input("Press Enter to exit and close the figure...")

カテゴリ

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