1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: MATLAB fprintf function

  1. Jul 1, 2009 #1
    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?
  2. jcsd
  3. Jul 1, 2009 #2


    Staff: Mentor

    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.
  4. Jul 1, 2009 #3


    User Avatar
    Science Advisor

    IIRC, MATLAB's fprintf command is supposed to have the same functionality as in C. Regarding those particular control characters, however:

    Form feed \f:

    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):
  5. Jul 6, 2009 #4
    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook