fprintf seems to ignore semicolon
10 views (last 30 days)
Show older comments
As the title reveals, when I use "fprintf" with a semicolon at the end, the argument in fprintf command seems to appear normally in command window. Is it just because fprintf command is designed to ignore in purpose the semicolon or something else?
I just noticed that "disp" behaves the same way as "fprintf". I know that I could use a "%" at the beginning of "fprintf". I just want to know about this behaviour.
0 Comments
Accepted Answer
Image Analyst
on 26 Feb 2015
I don't understand the problem. fprintf() does not return any value unless you're using a file handle. If you use no file handle, or a file handle of 1 (which is the command window), then it will just do it's job of printing your stuff to the command window but not return any additional value. It will not behave any differently if there is or is not a semicolon at the end of the line, just as expected and designed. So, yeah it ignores it - just like it should. Do you expect differently for some reason?
Now if you did use a file handle and printed to a disk file, then using a semicolon would not print anything to the command window, but leaving off the semicolon would print (in the command window) the number of bytes written to the disk file. In this case having or not having a semicolon does display things differently in the command window, and the semicolon is NOT ignored, again just as expected.
I don't see any confusion or discrepancy in the way it works. I hope that explains it better.
3 Comments
Stephen23
on 23 May 2020
"As fprintf does not have any return value"
Not quite: it actually returns the numbers of bytes printed.
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!