Sending input() from Python API

조회 수: 5 (최근 30일)
Adam Busch
Adam Busch 2019년 1월 12일
답변: Sean de Wolski 2021년 12월 28일
I am trying to allow for a user to interact with MATLAB scripts from the python console using the matlab engine API for python.
I am currently able to display the output of a script with the following code.
main.py
import matlab.engine
eng = matlab.engine.start_matlab()
eng.testInput(nargout=0)
testInput.m
prompt("Enter a number: ")
Whenever this runs, the console is frozen with the text
"Enter a number: " and I am unable to interact with the terminal.
I would expect that if the APi uses the python sys.stdout for displaying the output from the scripts that it would also allow for you to use the sys.stdin from the terminal.

답변 (2개)

Jasmine Dai
Jasmine Dai 2019년 1월 14일
Based on the documentation below:
It seems that user input is not supported by the engine API. I would suggest you provide any user input that you need on the python side and feed them into the engine calls.
  댓글 수: 1
sepand soltani
sepand soltani 2021년 12월 28일
Can't this confusion be prevented by giving an error to the user when an input functions(input(),keyboard(),..) is called from an engine?

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


Sean de Wolski
Sean de Wolski 2021년 12월 28일
This works if you start the MATLAB engine with the desktop:
import matlab.engine
eng = matlab.engine.start_matlab('-desktop')
s = eng.input("Hello World: ", "s")
print(s)
eng.quit()

카테고리

Help CenterFile Exchange에서 Call MATLAB from Python에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by