get MATLAB-inside-Python output redirected to Python in real-time
45 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Anna
el 27 de Nov. de 2025 a las 20:22
when i use the matlabengine Python package to launch MATLAB in Python code and run a MATLAB function, I redirect its output to a string stream that gets displayed on my Python GUI application's console like this:
import matlab.engine
adapter = MatlabStdoutToLogger()
engine: MatlabEngine = matlab.engine.start_matlab()
engine.func(..., nargout=0, stdout=adapter)
however, i don't get real-time output from the MATLAB script: it only gets printed at the end of MATLAB function's execution.
i need to see the output of fprintfs or disps i put in my MATLAB function which report execution progress in real-time. i need to know how much time will it take to finish, to be able to ditch experiments that take an eternity to compute.
so far i see only the vice-versa question like here: https://www.mathworks.com/matlabcentral/answers/2019676-return-print-statement-output-from-python-file-in-real-time-when-using-pyrunfile however, it deals with the same problem but for Python running in MATLAB, not MATLAB running in Python.
what can you recommend to fix this? it appears like something to do with buffering. i asked AI assisstants already but to no avail, they recommended drawnow('update') to flush MATLAB's output, but when i put these after printing statements, nothing gets displayed in my Python real-time, i again need to wait for the MATLAB execution to finish.
2 comentarios
Torsten
el 27 de Nov. de 2025 a las 20:41
Editada: Torsten
el 27 de Nov. de 2025 a las 20:41
Can you give a link on how execution progress of a MATLAB function (only in MATLAB itself, without Python communication) can be reported ? I've never heard of such a facility - most probably because execution time will be strongly problem-dependent and usually cannot be foreseen. Or do I misunderstand your question ?
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Call MATLAB from Python en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!