MATLAB: Does FPRINTF return an error when the file identifier 0 is specified in MATLAB 7.3 (R2006b)

fileidentifierMATLABprintprintf

The FPRINTF function returns an error if the fid value is specified as 0 in MATLAB 7.3 (R2006b). In previous releases we have used a file identifier value of 0 when it was necessary to suppress printing to the command window.
fprintf(1, 'I use this to supress printing to the Command Window\n')
produces an output:
I use this to supress printing to the Command Window
However, the statement:
fprintf(0, 'I use this to supress printing to the Command Window\n')
produces the following error:
??? Error using ==> fprintf
Operation is not implemented for requested file identifier.

Best Answer

This error was deliberately introduced in MATLAB 7.3 (R2006b) as the previous behavior was incorrect. The documentation for MATLAB 7.2 (R2006a) does not state that a file identifier (fid) value of 0 is allowed by the FPRINTF function. The valid file identifier values are only those returned by the FOPEN function as well as 1 (for stdout) and 2 (for stderr).
A file identifier value of 0 indicates stdin and printing out to stdin is not correct. In previous releases no action was taken when a file identifier value of 0 was specified, but it was not clear to users that an fid value of 0 is in fact incorrect. Thus, the error has been added to make that clear.