How do I print text to the MATLAB command window from a FORTRAN MEX file?

4 次查看(过去 30 天)

采纳的回答

MathWorks Support Team
Use mexPrintf to print to the MATLAB command window when using MEX files. Two examples are shown below.
Example 1: Print "API says hello!" to the MATLAB command window
#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
C Specify alert to be printed
character (len=*), PARAMETER :: txt = "API says hello!"
C Call the API
call mexPrintf(txt)
end
Example 2: Print the number of input arguments to the MATLAB command window:
#include "fintrf.h"
subroutine mexFunction(nlhs, plhs, nrhs, prhs)
character (len=1) :: c
character (len=50) :: txt
C Specify alert to be printed
write(txt,'(A)') 'Number of inputs (mexPrintf): '
C Convert nrhs to char
write(c,'(i1)') nrhs
C Call the API
call mexPrintf(txt)
call mexPrintf(c)
end
There are many FORTRAN MEX function source code examples available at:
Look in the table for examples with the .F file extension.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fortran with MATLAB 的更多信息

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by