Mastering MATLAB's fprintf Function: A Comprehensive Guide

  • Thread starter Thread starter Dell
  • Start date Start date
  • Tags Tags
    Function Matlab
AI Thread Summary
The discussion centers on the use of MATLAB's fprintf function, particularly regarding the escape sequences \f (form feed) and \b (backspace). Users express confusion about how these functions operate in MATLAB compared to their use in ANSI C, noting that \f does not effectively create a new page on a monitor and \b only moves the cursor back one character without deleting text. The conversation highlights that both escape codes have limited practical application in modern programming environments, especially on screens. A user provides links to documentation for further clarification on fprintf in MATLAB. Overall, the thread emphasizes the differences in functionality between printing to a file and displaying output on a screen.
Dell
Messages
555
Reaction score
0
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?
 
Physics news on Phys.org
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
 
Dell said:
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?

Mark44 said:
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
 
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.
 

Similar threads

Replies
3
Views
1K
Replies
4
Views
5K
Replies
1
Views
2K
Replies
2
Views
4K
Replies
7
Views
2K
Replies
7
Views
2K
Replies
4
Views
1K
Back
Top