Home

How to Use Special Characters in MATLAB

|
|  Updated:  
2016-03-26 08:21:54
|   From The Book:  
MATLAB For Dummies
Explore Book
Buy On Amazon

Sometimes you need to use special characters and character formatting in MATLAB. Here, you find out how to add Greek letters to your output, as well as work with superscript and subscript as needed.

Greek letters

The 24 Greek letters are used extensively in math. To add these letters to MATLAB, you must use a special escape sequence.

Letter Sequence Letter Sequence Letter Sequence
@@lcalp alpha @@lcbeta beta ã gamma
@@lcdel delta @@lceps epsilon @@lczeta zeta
@@lceta eta @@lctheta theta @@iota iota
@@lckap kappa @@lclam lambda ì mu
@@lcnu nu @@lcxi xi @@lcomi Not Used
ð pi @@lcrho rho @@lcsig sigma
@@lctau tau @@lcups upsilon @@lcphi phi
@@lcchi chi @@lcpsi psi @@lcomega omega

As you can see, each letter is preceded by a backslash, followed by the letter’s name. The output is always lowercase Greek letters. Notice that omicron (@@lcomi) has no sequence. To see how the letters appear onscreen, type TBox10 = annotation(‘textbox’, [.13, .39, .17, .085], ‘String’, ‘alphabetagammadeltaepsilonzetaetathetaiotakappalambdamu nuxipirhosigmatauupsilonphichipsiomega’, ‘BackgroundColor’, [.5, .5, 1]); and press Enter.

Many of the Greek letters are also available in uppercase form. All you need to do is use initial caps for the letter name. For example, gamma produces the lowercase letter, but Gamma produces the uppercase version of the same letter. You can obtain additional information about text properties (including additional symbols that you can use) at MathWorks.com.

image0.jpg

Superscript and subscript

Using superscript and subscript as part of the output is essential when creating formulas or presenting certain other kinds of information. MATLAB uses the caret (^) to denote superscript and the underscore (_) to denote subscript. You enclose the characters that you want to superscript or subscript in curly brackets {}.

To see how superscript and subscript works, type TBox11 = annotation(‘textbox’, [.45, .39, .15, .075], ‘String’, ‘Normal^{Super}_{Sub}’, ‘BackgroundColor’, [.5, .5, 1]); and press Enter.

Notice that the superscript and subscript characters appear in the command without a space after the characters that are in normal type. The output shows these characters immediately after the normal type. In addition, the superscripted characters are over the top of the subscripted characters.

image1.jpg

About This Article

This article is from the book: 

About the book author:

Jim Sizemore is Professor of Physics and Engineering at Tyler Junior College. For over 25 years he s worked in the semiconductor and software industries as a process engineer, device physicist, and software developer and has been teaching college physics, engineering, and math for the last 13 years.

John Paul Mueller is a freelance author and technical editor. He has writing in his blood, having produced 100 books and more than 600 articles to date. The topics range from networking to home security and from database management to heads-down programming. John has provided technical services to both Data Based Advisor and Coast Compute magazines.