I find that I often want to either print control characters or print out prettier output than can easily be done with just the built-in disp function. I've written a wrapper around fprintf that outputs to stdout and included stdout and stderr functions. What this allows you to do is replace code like:
fprintf(1, 'My result is: %d', foo);
with cleaner code like
printf('My result is: %d', foo);
The code has been tested on MATLAB 12.1 and 13, but I'd have a hard time believing it doesn't work on much older versions.
you are using matlab inbuilt fprintf function
to diaplay the output data to cmd window,can you able to write your own fprintf function??
25 Jun 2008
06 Aug 2007
Thanks! Very handy for me, especially when I just want to run through a bunch of arrays and print out nicely formatted summaries of them without having to do some workaround with fprintf. Well done!
07 Jun 2007
Response to Ambarish Mitra:
On all versions that I use, 'stdout' prints before 'stderr', though I'm not especially surprised to see it happen the other way. In most languages, stdout is buffered for efficiency purposes and stderr is not buffered since you typically want to know about errors right away. This means that sometimes stderr messages that were submitted later will print out on the screen before later stdout messages. In C/C++, Perl, etc. it's common to use fflush(stdout) whenever these issues arise. I don't see an fflush function in Matlab or a description of its buffering behavior in the documentation, but I suspect that's what your seeing.
In this, I expect that first "stdout" will be printed, then "stderr". However, I observe the opposite.
Can you please explain the output?
16 Feb 2006
Mixel Plick is indeed correct.
is the same as
printf('foo') % downloaded here
fprintf(stdout, 'foo'); % downloaded here
I'm not removing this file because the download rate to me indicates that many other people have missed the fact that fprintf is overloaded to work like printf. stdout and stderr can also be useful for self-documentation purposes for some people. For most people, you'll want to follow Mixel's suggestion and just use fprintf.
24 May 2004
You must not unaware that if you are printing to stdout with fprintf, you can omit the file number, e.g.,