Why does FPRINTF return an error when the file identifier 0 is specified in MATLAB 7.3 (R2006b)?

4 views (last 30 days)
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.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
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.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products


Release

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!