engSetVisible when starting Matlab Engine from Python

Hello, when starting Matlab Engine from C++ it was possible to have the engine window visible, and keep it open even after the code was finished, so easy debugging of the workspace content of the engine session was possible. When starting the matlab engine from python, the engSetVisible command does not work and a startup option ("-visible") is not understood. Is there a solution to this? I am aware that a possible workaround is to save the workspace at the end of the script and then reload it. Just this is less convenient than having the workspace open and accessible straight away. Thanks a lot

 채택된 답변

Robert Snoeberger
Robert Snoeberger 2015년 5월 31일

0 개 추천

According to the documentation, you can start matlab with the "-desktop" startup option. See the "Start Engine with Startup Options" subsection of the documentation for more information.
Please note that startup options were added in R2015a. See "MATLAB Engine for Python: Support for startup options" in the R2015a release notes .

댓글 수: 4

EK
EK 2015년 5월 31일
편집: EK 2015년 5월 31일
Thank you for the fast response. In my particular context I found this option little helpful: The desktop opens, but it closes again automatically after program execution, i.e. after several seconds. The likely reason is that I call python from a third party-script:
3rdpartyapplication -> calls python script --> python script opens matlab engine session --> python script enables data exchange between 3rdparty-app and matlab -> execution of python script complete -> execution of third party application complete
Matlab Desktop has closed automatically. A debug option is not available in the third-party script, so I cannot pause program execution to study the matlab engine workspace
Can you use dbstop to set a breakpoint in the M file you are calling from Python?
Assume the M file "foo.m" is located in folder "C:\tmp", this is one approach that I would try:
>>>eng=matlab.engine.start_matlab("-desktop")
>>>eng.cd(r'C:\tmp') #change to the folder with file "foo.m"
>>>eng.eval("dbstop in foo.m at 2", nargout=0) #set breakpoint
>>>eng.foo() #call the M function, which will pause at line 2
After that, you can check the variables in the workspace of MATLAB.
Thank you Robert and Bo: The dbstop is a helpful command. Still, here, the script would not stop at the desired point. What I'm doing now is to pause the python script: #import time
time.sleep(1)
In this way, I can inspect the contents of the matlab engine session and it will not be closed automatically

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

제품

질문:

EK
2015년 5월 31일

댓글:

EK
2015년 6월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by