MATLAB: How to enable a debug output in the Embedded MATLAB function in Simulink 7.6 (R2010b)

simulink

I would like to have a second debug output argument in my Embedded MATLAB function that is only present when the original .m file is executed. In other words, I want the C code generated from this .m file to have no trace of the extra debug output argument.

Best Answer

The attached files demonstrate how to accomplish this goal.
Here is the generated code when debugMode is true:
void debugit(real_T n, real_T y[10], real_T debug[100])
{
int32_T i;
memset((void *)&debug[0], 0, 100U * sizeof(real_T));
memset((void *)&y[0], 0, 10U * sizeof(real_T));
i = 1;
while ((real_T)i <= n) {
y[emlrtBoundsCheckR2011a(i, &emlrtBCI, &emlrtContextGlobal) - 1] = (real
_T)i;
debug[i - 1] = y[i - 1];
i++;
emlrtBreakCheck();
}
}
Here is the generated code when debugMode is false:
void debugit(real_T n, real_T y[10])
{
int32_T i;
memset((void *)&y[0], 0, 10U * sizeof(real_T));
i = 1;
while ((real_T)i <= n) {
y[emlrtBoundsCheckR2011a(i, &emlrtBCI, &emlrtContextGlobal) - 1] = (real
_T)i;
i++;
emlrtBreakCheck();
}
}
The trick here is to use constant empty matrices to ensure the variable is fully eliminated.