MATLAB: How to use FPRINTF to send a special character to an instrument with the Instrument Control Toolbox

charactercontrolfprintfinstrumentInstrument Control Toolboxspecialtoolbox

As indicated in the following documentation on FPRINTF:
fprintf (Instrument Control Toolbox)
The calling syntax:
fprintf(obj,'format','cmd')
writes the string 'cmd' to the instrument connected to obj using the format specified by 'format'.
FPRINTF may also be called as in:
fprintf(obj,'cmd')
In this syntax, FPRINTF writes the string 'cmd' directly to the instrument connected to obj.
However, when I execute the following command
fprintf(g2,'FT1<\r\n');
FPRINTF does not transmit my control sequence '\r\n'. Instead it converts then directly to double values. The '\r' sequence is only evaluated to 13 if it is in the format string, but not if it is in a string passed to the format string.

Best Answer

The command
fprintf(g2,'FT1<\r\n');
is actually shorthand for
fprintf(g2, '%s\n', 'FT1<\r\n');
where '%s\n' is the default format string, because it is not explicitly specified.
For the '\r' to be evaluated, you can use
fprintf(g2, '%s\r\n', 'FT1<');
.