- Redirecting stdout and stderr to StringIO stream (see example below)
- Having a console window visible
- Removing all disp functions from matlab code
Matlab Runtime "Error on flush"
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to use Python and MATLAB Runtime to call some code that was previously compiled using the MATLAB compiler. It's giving me the following error:
MatlabRuntimeError: An error occurred when evaluating the result from a function. Details: Error on flush.
Googling the error didn't turn anything up. Does anyone know what this might mean? I have double-checked that I am using the correct version of the compiler (9.4 R2018a), and I get the same error message whether I'm using Python 2.7 or 3.6. The MATLAB code works fine when run from MATLAB proper.
Any help would be very much appreciated!
0 commentaires
Réponses (4)
Olli Tanskanen
le 4 Août 2020
I encountered the issue as well.
I was able to reproduce the issue reliably when using pyinstaller with console option set to false (when false it won't show a console window, only your applicaton window), but when I ran the pyinstaller with console option set to true everything worked just fine. The bug seems to be related to stdout not 'existing' which causes issues in matlab side.
I was able to fix the problem with any of these:
Example on how to redirect stdout:
import io
import your_matlab_package
p_handle = your_matlab_package.initialize()
p_handle.your_matlab_function(..., stdout=io.StringIO(), stderr=io.StringIO())
If you want to actually show matlab disp results in python side you can of couse create a new class which inherits StringIO and override the write function where you would actually show/log the matlab output.
1 commentaire
W Grootjans
le 25 Août 2025
Thanks for this response. This fixed my problem for this very niche use case. Very much appreciated!!!
Andreas Blassnig
le 7 Nov 2018
Could you find a solution for this Problem? (I got the same error message.)
Best regards
kok wei
le 10 Juin 2019
I'm facing this issue with MATLAB R2019a and Python 3.6.8 as well. Appreciate for any further inputs.
0 commentaires
yusuf elezler
le 14 Avr 2020
Modifié(e) : yusuf elezler
le 14 Avr 2020
The problem is display functions like disp('xxxx'). Delete or comment it and compile again. It'll work.
0 commentaires
Voir également
Catégories
En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!