How can I use "mexPrintf" for simulation and "printf" for code generation in a MATLAB Function Block using coder.ceval?
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
MathWorks Support Team
el 12 de Oct. de 2018
Respondida: MathWorks Support Team
el 24 de Jun. de 2019
I am using a MATLAB Function block in my Simulink model. My MATLAB function calls a custom C functions using "coder.ceval". I want to use "mexPrintf" in my C function during simulation but the standard C "printf" when building the model. How can I do this?
Respuesta aceptada
MathWorks Support Team
el 25 de Jun. de 2019
You can use the "MATLAB_MEX_FILE" C preprocessor macro in your custom C code to determine whether you are compiling for a MEX target. For example, you can use this macro to define a custom "printOutput" function:
#include <stdio.h>
#include <stdlib.h>
#ifdef MATLAB_MEX_FILE
#include "mex.h"
#endif
void printOutput(const char* str);
#ifdef MATLAB_MEX_FILE
// Use the mexPrintf function
void printOutput(const char* str) {
mexPrintf(str);
}
#else
// Use the standard C printf function
void printOutput(const char* str) {
printf(str);
}
#endif
This function is defined to call "mexPrintf" when compiled for a MEX and "printf" otherwise.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Simulink Coder 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!