MATLAB For Dummies
Book image
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 authors:

John Paul Mueller is an author and technical editor with experience in application development, database management, machine learning, and deep learning. He has written hundreds of books and articles helping everyday people learn everything from networking to database management.

John Mueller has produced 114 books and more than 600 articles on topics ranging from functional programming techniques to working with Amazon Web Services (AWS). Luca Massaron, a Google Developer Expert (GDE),??interprets big data and transforms it into smart data through simple and effective data mining and machine learning techniques.

This article can be found in the category: