Download Getting Started with MATLAB 7

Transcript
4
Programming
Internally, the characters are stored as numbers, but not in floating-point
format. The statement
a = double(s)
converts the character array to a numeric matrix containing floating-point
representations of the ASCII codes for each character. The result is
a =
72
101
108
108
111
The statement
s = char(a)
reverses the conversion.
Converting numbers to characters makes it possible to investigate the various
fonts available on your computer. The printable characters in the basic ASCII
character set are represented by the integers 32:127. (The integers less than
32 represent nonprintable control characters.) These integers are arranged in
an appropriate 6-by-16 array with
F = reshape(32:127,16,6)';
The printable characters in the extended ASCII character set are represented
by F+128. When these integers are interpreted as characters, the result
depends on the font currently being used. Type the statements
char(F)
char(F+128)
and then vary the font being used for the Command Window. Select
Preferences from the File menu to change the font. If you include tabs in
lines of code, use a fixed-width font, such as Monospaced, to align the tab
positions on different lines.
Concatenation with square brackets joins text variables together into larger
strings. The statement
h = [s, ' world']
4-14