Displaying progress from a file compiled to MEX with MATLAB Coder.
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
Denis Gurchenkov
2016년 10월 25일
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
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!