MATLAB: Matlab Coder and Ceval

guess the real outputmatlab coder coder.ceval

I'm trying to use matlab coder and would like to display some text on the terminal from which I run the compiled C code. I'm having issues with the simple printf
The code in matlab is:
for n=2:10
coder.ceval('printf','%d',n);
end
where n is the thing I want to print out to teh screen
The code I end up getting is:
static const char_T cv0[2] = { '%', 'd' };
char_T cv1[2];
n=2;
while (n <= 10)
for (i0 = 0; i0 < 2; i0++) {
cv1[i0]=cv0[i0];
}
printf(cv1, (real_T)n);
which does not seem to output the value of n, but instead just 0s
The code I WANT is:
printf("%d",n);
which does what I want when I put it in the .c file myself and compile
Any help would be appreciated

Best Answer

Try:
for n=2:10
coder.ceval('printf','%d ',int32(n));
end
or
for n=2:10
coder.ceval('printf','%f ', n);
end
In MATLAB, 'n' is double by default.
EDIT:
To pass in a newline character, you can use the ASCII value (=10 for \n):
formatString = ['%d' char(10)];
for n=2:10
coder.ceval('printf', formatString, int32(n));
end