Displaying progress from a file compiled to MEX with MATLAB Coder.

2 visualizaciones (últimos 30 días)
Tom Holden
Tom Holden el 9 de Oct. de 2016
Respondida: Denis Gurchenkov el 25 de Oct. de 2016
I have a slow running .m file that I am compiling to MEX via MATLAB Coder.
I would like to display the loop counter in the code's main loop.
However, with an fprintf, nothing is getting printed until the function exits.
I have tried the following, but even this does not fix the problem completely:
if ~coder.target( 'MATLAB' )
coder.cinclude( 'fflushStdOut.h' );
end
...
fprintf( '%d\n', NSample );
if ~coder.target( 'MATLAB' )
coder.ceval( 'fflushStdOut', int32( 0 ) );
end
drawnow update;
Where fflushStdOut.h contains:
#ifndef FFLUSH_STD_OUT_H
#define FFLUSH_STD_OUT_H
#define fflushStdOut( x ) fflush( stdout );
#endif
Even with this, the function is still not displaying anything until 1800+ iterations have past, which takes a good 30 minutes.
Any ideas?

Respuestas (1)

Denis Gurchenkov
Denis Gurchenkov el 25 de Oct. de 2016
A combination of 'drawnow' and 'mexPrintf' seem to work:
function test1
coder.extrinsic('drawnow');
for i = 1:1000
coder.ceval('mexPrintf', ['hello' 10 0]);
drawnow();
coder.ceval('Sleep', int32(100));
end
end
codegen test1 -config:mex
test1_mex
Prints 'hello' every 0.1 seconds

Categorías

Más información sobre MATLAB Coder en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by