View Full Version : MATLAB fprintf function
i am learning matlab and last week we learned the fprintf function, both for printing to the screen and for printing to file, though we only practised printing to screen,
reading over my notes i see the \f -form feed- and \b -backspace- functions, and cannot figure out what they do,,, i tried looking for them in the help file but didnt help.
i tried making a .txt file and using fprintf to write to it, then tried using \f and \b, but all they did was make a gap at the end of my previous text and then added whatever new text i wrote,, if that is what they do then how are they different to \t?
I don't know much about MATLAB, but the fprintf function is very similar to the function of the same name from ANSI C, which I am quite familiar with. In C the fprintf function does formatted printing to a file, and since a computer display is significantly different from a printer, there are some differences. The \f and \b escape codes are form-feed and backspace (as you said). I seem to remember that \f was used to move the paper in a printer so that the next output started on a new page. If I'm remembering correctly it didn't have that much effect on a computer monitor. The \b character was supposed to move the print head back one character.
Here's a link to some documentation on fprintf as used in MATLAB. Hope that is helpful.
Mark
MATLABdude
Jul1-09, 07:15 PM
i am learning matlab and last week we learned the fprintf function, both for printing to the screen and for printing to file, though we only practised printing to screen,
reading over my notes i see the \f -form feed- and \b -backspace- functions, and cannot figure out what they do,,, i tried looking for them in the help file but didnt help.
i tried making a .txt file and using fprintf to write to it, then tried using \f and \b, but all they did was make a gap at the end of my previous text and then added whatever new text i wrote,, if that is what they do then how are they different to \t?
I don't know much about MATLAB, but the fprintf function is very similar to the function of the same name from ANSI C, which I am quite familiar with. In C the fprintf function does formatted printing to a file, and since a computer display is significantly different from a printer, there are some differences. The \f and \b escape codes are form-feed and backspace (as you said). I seem to remember that \f was used to move the paper in a printer so that the next output started on a new page. If I'm remembering correctly it didn't have that much effect on a computer monitor. The \b character was supposed to move the print head back one character.
Here's a link to some documentation on fprintf as used in MATLAB. Hope that is helpful.
Mark
IIRC, MATLAB's fprintf command is supposed to have the same functionality as in C. Regarding those particular control characters, however:
Form feed \f:
http://en.wikipedia.org/wiki/Form_feed
Backspace \b (when you sea^H^H^H see ^H on the internet, it's an (old) geek joke meaning that they wanted to delete a character or few before you could see it):
http://en.wikipedia.org/wiki/Backspace
Nick Bruno
Jul6-09, 01:45 PM
I took an aerodynamics class last year and my professor gave us a few projects to get us familiar with matlab writing abilities.
I can send you these files if you would like. I just need an email to send it to. Thanks.
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.