Mastering MATLAB's fprintf Function: A Comprehensive Guide

  • Thread starter Thread starter Dell
  • Start date Start date
  • Tags Tags
    Function Matlab
Click For Summary

Discussion Overview

The discussion revolves around the use of the fprintf function in MATLAB, particularly focusing on the escape sequences \f (form feed) and \b (backspace). Participants explore their functionality, differences from other escape sequences like \t (tab), and their behavior when printing to files versus screens.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant expresses confusion about the \f and \b escape sequences in MATLAB's fprintf function, noting that they did not find helpful information in the help file.
  • Another participant, familiar with ANSI C, explains that \f is traditionally used to move to a new page in printers, while \b is meant to move the print head back one character, suggesting these may not have significant effects on computer monitors.
  • A participant mentions that they experienced gaps when using \f and \b in a text file, questioning how they differ from \t.
  • A later reply provides links to Wikipedia articles for further context on the form feed and backspace characters.
  • One participant offers to share MATLAB project files from an aerodynamics class, indicating practical applications of the fprintf function.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the specific effects of the \f and \b escape sequences in MATLAB, and multiple interpretations of their functionality are presented.

Contextual Notes

There is uncertainty regarding the practical effects of the \f and \b escape sequences in the context of MATLAB, particularly when compared to their historical use in printing. The discussion does not resolve the differences between these escape sequences and \t.

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 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K