Chapter 17

Printing and Publishing Your Work

IN THIS CHAPTER

check Modifying the appearance of text

check Creating a MATLAB data publication

check Sending your data to the printer

After you have labored long to create the next engineering marvel or produce the next scientific breakthrough, you really do want others to know about it. Most people want to shout about their achievements from the mountaintops, but this chapter tells you only how to publish and print them. Publishing is electronic output of your data; printing is the physical output of your data. Whether you publish or print your data, it becomes available in a form that other people can use, even if they don’t own a copy of MATLAB.

Part of the publishing and printing process is to make the information aesthetically appealing. It doesn’t matter how impressive the data is if no one can read it. Formatting information is part of the documentation process because people need cues about the purpose of the text they’re seeing. To that end, this chapter helps you create nicely formatted electronic publications and printed documents.

Remember You don’t have to type the source code for this chapter manually. In fact, using the downloadable source is a lot easier. You can find the source for this chapter in the \MATLAB2\Chapter17 folder of the downloadable source. When using the downloadable source, you may not be able to work through some of the hands on examples because the example files will already exist on your system. In this case, you can create an alternative folder, Chapter17a, to hold the results of the hands on exercises.

Using Commands to Format Text

Presentation is a large part of how people receive and understand the material you provide. The same information, presented in two different ways, will elicit different responses from the audience. Little things, such as adding bold type to certain elements, can make a subtle but important difference in how the information is grasped by the audience.

Remember This book isn’t about desktop publishing or creating professional-level presentations. In the following sections, you discover some ideas on how to dress up the appearance of your data so that an audience can see the data in a certain light. You can use various text effects to add emphasis where needed or to point out a particular element of interest. You can also use special symbols to add explanatory text so that the data is more easily understood.

Modifying font appearance

The fonts you use or misuse can say a lot about your presentation. Unfortunately, fonts are more often misused than used effectively to convey ideas. Here are the four ways in which you can modify the appearance of fonts in MATLAB to good effect:

· Bold: Adds emphasis so that the viewer sees the affected text as being more important than the text around it. However, bold is also used for headings to provide separation between elements. Always think of bold as grabbing the attention of the viewer in some way.

· Monospace: Creates an environment in which text elements line up, as when using a typewriter. Most people use monospace for code, or for numeric data presented free-form as a table, because monospace helps present a neat appearance. The viewer sees the data rather than being distracted by the data’s lack of alignment.

· Italic: Defines elements that are special in some way but don’t require emphasis. For example, if you define a term inline with the remainder of your data, the term should appear in italics to cue the viewer that it is explained in the material that follows. The point of italic type is to give your viewer cues about added material rather than to add emphasis.

· Underline: Provides pointers to additional resources or other external information (such as the URLs found in Web pages). Some people use an underline for emphasis as well, but this is actually a misuse of an underline because you already have bold to emphasize something. Combining bold and underline is even worse because the recipient can perceive it as shouting. Use underline as a means of pointing to other data that the viewer should know about but that doesn’t appear in your presentation.

LISTING THE AVAILABLE FONTS

At some point, you need to know how to obtain a list of fonts available on the local system. To do so, you use the listfonts() function. To see how this function works, type Fonts = listfonts(); and press Enter. The Fonts variable receives a sorted list of fonts on the current system, which you can then search for appropriate values. To find a specific font, such as Arial, type Found = find(strcmp(Fonts, 'Arial')); and press Enter. If Found isn’t empty after the call (in other words, length(Found) returns a value greater than 0), the system supports the font you want to use.

Some elements can have special fonts in MATLAB. To discover the identity of the special font, you call listfonts() with the handle of the element. For example, a user interface element may have a special font. If you obtain a handle to that user interface element and pass it to the listfonts() function, you receive not only a sorted list of the system fonts but also the identity of the special font used in the user interface element.

Remember You can probably find other opinions as to how to use various font styles, but this is the approach used by many (if not most) technical documents, so your viewer will already know the rules. Keeping things familiar and easy to understand will help the viewer focus on your data rather than on the fonts and styles you use. Always make the data king of the presentation and leave the beautiful text to the artists of the world.

Now that you have some idea of how to use the font styles, the following sections demonstrate how to add them to your presentation. The screenshots in each section build on the section before it so that you can see all the effects in action. You don’t have to work through the sections in any particular order.

Bold

The use of emphasis, normally associated with bold type, can make data stand out. However, in MATLAB, the term bold actually refers to font weight. The strength of the font you use provides a level of emphasis. In fact, you can set a font to four different levels of emphasis:

· Light

· Normal (default)

· Demi

· Bold

Remember Not every font that you have installed on your system supports all four levels of emphasis, but at least some do. You may try to achieve a certain level of emphasis with a font and find your efforts thwarted. In many cases, it has nothing to do with your code and everything to do with the font you’re using. To see what levels of support your font has, you can open the Fonts window in the Windows Control Panel to see the list of fonts that your system supports. Double-click the font you want to check, such as Arial (shown in Figure 17-1, your view may vary depending on your version of Windows), and you see that Arial doesn’t support a light or demi font version. However, you could use this arrangement if you want to mimic having all four levels of emphasis:

· Light: Arial Narrow

· Normal: Arial Regular

· Demi: Arial Bold

· Bold: Arial Black

Snapshot of determining the levels of emphasis your font will support.

FIGURE 17-1: Determining the levels of emphasis your font will support.

With these font limitations in mind, the following steps help you see the varying levels of emphasis that you can achieve using MATLAB. (You can find all of the steps for this and the following sections in the GeneratePlotFormatting.m script provided with the downloadable source.)

1. Type Bar1 = bar([5, 15, 8, 2, 9]); and press Enter.

MATLAB creates a new bar chart.

2. Type TBox1 = annotation('textbox', [.13, .825, .14, .075], 'String', 'Light', 'FontName', 'Arial Narrow', 'FontSize', 16, 'FontWeight', 'light', 'BackgroundColor', [1, 1, 0]); and press Enter.

You see a new annotation of type textbox added to the plot. The various entries that you typed change the default font, the font size (so that you can more easily see the text), the font weight (as a matter of emphasis), and the background color (so that the textbox stands out from the bars in the background). To see the various weights side by side, the next few steps add three more textboxes, each with a different font weight.

3. Type TBox2 = annotation('textbox', [.29, .825, .14, .075], 'String', 'Normal', 'FontName', 'Arial', 'FontSize', 16, 'FontWeight', 'normal', 'BackgroundColor', [1, 1, 0]); and press Enter.

You see the next annotation placed on the second bar. In most cases, you won’t see much (or any) difference between the light and normal settings because few fonts support both light and normal. However, some do, so it’s important to experiment.

4. Type TBox3 = annotation('textbox', [.45, .825, .14, .075], 'String', 'Demi', 'FontName', 'Arial', 'FontSize', 16, 'FontWeight', 'bold', 'BackgroundColor', [1, 1, 0]); and press Enter.

5. Type TBox4 = annotation('textbox', [.61, .825, .14, .075], 'String', 'Bold', 'FontName', 'Arial Black', 'FontSize', 16, 'FontWeight', 'normal', 'BackgroundColor', [1, 1, 0]); and press Enter.

You see the final annotation placed on the plot. Looking at the four different annotations, you can see a progression of weights and emphasis. Even though you may not see much difference between light and normal, the weight differences among normal, demi, and bold are pronounced, as shown in Figure 17-2.

Monospace

A monospace font is one in which the characters take up precisely the same amount of space. It’s reminiscent of the kind of text that typewriters put out. (If you don’t know what a typewriter is, check out https://site.xavier.edu/polt/typewriters/tw-history.html.) Monospace is still useful because it makes getting elements to line up easy. That’s why code is often presented in monospace: You can easily see the indentation that the code needs to look nice and work properly. The way that monospace is set for an element is through the font. Here are some commonly used monospace fonts:

· Anonymous Pro

· Courier

· Courier New

· Fixedsys

· Letter Gothic

· Lucida Sans Typewriter Regular

· Lucida Console

· Monaco

· Profont

· Ubuntu

Snapshot of the different font weights provide different levels of text emphasis.

FIGURE 17-2: Different font weights provide different levels of text emphasis.

Tip You can see some additional monospace fonts at https://www.fontsquirrel.com/fonts/list/classification/monospaced. The point is to use a font that provides the proper appearance for your application. To obtain a monospace font appearance, you simply change the FontName property to a monospace font. For example, type TBox5 = annotation('textbox', [.13, .72, .15, .075], 'String', 'Monospaced', 'FontName', 'CourierNew', 'BackgroundColor', [0, 1, 1]); and press Enter to produce a text box containing monospace text (using the plot generated in the preceding section of the chapter). Figure 17-3 shows the results of this command.

Snapshot of monospace fonts make aligning text elements easy.

FIGURE 17-3: Monospace fonts make aligning text elements easy.

Italic

Fonts normally have a straight, up-and-down appearance. However, you can skew the font to give an angle to the upright characters and change how the font looks. The skewed version of a font is called italic. To create an italic font, the person creating the font must design a separate set of letters and place them in a file containing the italic version.

Remember Some fonts don’t have an italic version. When you encounter such a situation, you can ask the computer to skew the font programmatically. The font file hasn’t changed, and the font is still straight up and down, but it looks italicized onscreen. This version of italics is called oblique. The italic version of a font always gives a better visual appearance than the oblique version because the italic version is hand tuned — that is, individual pixels are modified so that the font appears smoother.

To configure a font for either italic or oblique, you use the FontAngle property. The following steps help you see the differences between the standard, italic, and oblique versions of a font. These steps assume that you have created the MATLAB plot found in the “Bold” section, earlier in this chapter.

1. Type TBox6 = annotation('textbox', [.13, .61, .14, .075], 'String', 'Normal', 'FontSize', 16, 'FontAngle', 'normal', 'BackgroundColor', [1, 0, 1]); and press Enter.

You see a textbox annotation containing a normal version of the default MATLAB font for your system.

2. Type TBox7 = annotation('textbox', [.29, .61, .14, .075], 'String', 'Italic', 'FontSize', 16, 'FontAngle', 'italic', 'BackgroundColor', [1, 0, 1]); and press Enter.

You see a textbox annotation containing either a normal or an italic version of the default MATLAB font for your system. The italic version appears only if the font happens to have an italic version (most do).

3. Type TBox8 = annotation('textbox', [.45, .61, .15, .075], 'String', 'Oblique', 'FontSize', 16, 'FontAngle', 'oblique', 'BackgroundColor', [1, 0, 1]); and press Enter.

You see a textbox annotation containing an oblique version of the standard font. Figure 17-4 shows all three versions. You may see a slight difference in angle between the italic and oblique versions. The oblique version may seem slightly less refined. Then again, you might not see any difference at all between italic and oblique.

Snapshot of italic and oblique versions of the same font could show subtle differences.

FIGURE 17-4: Italic and oblique versions of the same font could show subtle differences.

Underline

Interestingly enough, MATLAB doesn’t provide a simple method to underline text in plots (you find a perfectly acceptable underline in the Live Editor). For example, you can’t easily perform this particular task using the GUI. In fact, the default method of creating text using code doesn’t provide a method for underlining text, either. However, you have a way to accomplish the goal using a special interpreter called LaTeX (https://www.latex-project.org/).

The LaTeX interpreter is built into MATLAB, but it isn’t selected by default, so you must set it using the Interpreter property. In addition to underlining text, you use the \underline() LaTeX function. To see how this works, type TBox9 = annotation('textbox', [.13, .5, .175, .075], 'String', '\underline{Underline}', 'FontSize', 16, 'BackgroundColor', [.5, 1, .5], 'Interpreter', 'latex'); and press Enter. You see the output shown in Figure 17-5.

Snapshot of underlining text is a little harder than performing other formatting tasks.

FIGURE 17-5: Underlining text is a little harder than performing other formatting tasks.

Tip Notice that the output differs quite a bit when using the LaTeX interpreter. That’s because LaTeX ignores many of the formatting properties supplied by MATLAB — you must set them using LaTeX functions. However, the problem is more serious than simply setting a font because MATLAB appears to lack the required font files for LaTeX. The bottom line is that you should avoid underlining text unless you truly need to do so. Use bold, italic, and font colors in place of the underline as often as possible.

Using special characters

Sometimes you need to use special characters and character formatting in MATLAB. The following sections describe 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, similar to the escape sequences, such as \n for the newline character, that you use in previous chapters. Table 17-1 shows the sequences to use for Greek letters.

TABLE 17-1 Adding Greek Letters to MATLAB

Letter

Sequence

Letter

Sequence

Letter

Sequence

α

\alpha

β

\beta

γ

\gamma

δ

\delta

ε

\epsilon

ζ

\zeta

η

\eta

θ

\theta

ɩ

\iota

κ

\kappa

λ

\lambda

μ

\mu

ν

\nu

ξ

\xi

ο

Not Used

π

\pi

ρ

\rho

σ

\sigma

τ

\tau

υ

\upsilon

φ

\phi

χ

\chi

ψ

\psi

ω

\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 (ο) has no sequence, but you can replace it with the letter o. (Table 17-1 shows the lowercase Greek letters, but you can also create the uppercase Greek letters by using an initial capital letter, such as \Psi for the uppercase version of \psi.) To see how the letters appear onscreen, type TBox10 = annotation('textbox', [.13, .39, .51, .085], 'String', '\alpha\beta\gamma\delta\epsilon\zeta\eta\theta\iota\kappa\lambda\mu\nu\xi\pi\rho\sigma\tau\upsilon\phi\chi\psi\omega', 'FontSize', 16, 'BackgroundColor', [.5, .5, 1]); and press Enter. Figure 17-6 shows how your sample should look at this point.

Snapshot of MATLAB providing access to the various Greek letters normally used in formulas.

FIGURE 17-6: MATLAB provides access to the various Greek letters normally used in formulas.

Tip 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 https://www.mathworks.com/help/matlab/creating_plots/greek-letters-and-special-characters-in-graph-text.html.

Superscript and subscript

Using superscript and subscript as part of the output is essential when creating formulas or presenting certain kinds of other 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', [.70, .39, .15, .075], 'String', 'Normal^{Super}_{Sub}', 'BackgroundColor', [.5, .5, 1]); and press Enter. Figure 17-7 shows typical output from this command.

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.

Snapshot of working with superscript and subscript characters.

FIGURE 17-7: Working with superscript and subscript characters.

Adding math symbols

You would have a tough time presenting formulas to others without being able to use math symbols. MATLAB provides you with a wealth of symbols that you can use for output purposes. The following sections describe the most commonly used symbols and how you access them.

Fraction

Displaying what appears to be a fraction onscreen doesn’t always mean writing an actual numeric fraction; it could be a formula that requires that sort of presentation, such as one showing division. Whatever your need, you can display fractions whenever needed. However, to do that, you must use the LaTeX interpreter mentioned in the “Underline” section, earlier in the chapter. This means that your formatting options are limited and that the output won’t necessarily reflect the formatting choices you normally make when using MATLAB.

The fraction requires use of a LaTeX display style that you access using $\displaystyle\frac{}. The fraction itself appears in two curly brackets, such as {1}{2} for the symbol ½. The entry ends with another dollar sign ($). To see how fractions work with something a little more complex, type TBox12 = annotation('textbox', [.13, .28, .15, .085], 'String', '$\displaystyle\frac{x-2y}{x+y}$', 'BackgroundColor', [1, .5, .5], 'Interpreter', 'latex'); and press Enter. Figure 17-8 shows typical output from this command.

Snapshot of using fractions to display formulas correctly.

FIGURE 17-8: Using fractions to display formulas correctly.

Square root

MATLAB makes displaying a square root symbol easy. However, getting the square root symbol the right size, with the bar extended over the expression whose root is being taken, requires LaTeX. As with many LaTeX commands, you enclose the string that you want to format in a pair of dollar signs ($). The function used to perform the formatting is \sqrt{}, and the value that you want to place within the square root symbol appears within the curly brackets.

To see the square root symbol in action, type TBox13 = annotation('textbox', [.29, .28, .15, .085], 'String', '$\sqrt{f}$', 'BackgroundColor', [1, .5, .5], 'Interpreter', 'latex'); and press Enter. The variable f will appear in the square root symbol, as shown in Figure 17-9.

Sum

Displaying a summation formula complete with sigma and the upper and lower limit involves using LaTeX with the \sum:{} function. You supply all three elements of the display in a single statement: the lower limit first; the upper limit second; and the expression third. Each element appears in separate curly brackets. The lower limit is preceded by the underscore used for subscripts, and the upper limit is preceded by the caret used for superscripts. The entire statement appears within dollar signs ($), as is normal for LaTeX. However, in this particular case, you must include a second set of dollar signs or the expression doesn’t appear correctly onscreen. (The upper and lower limits don’t appear in the correct places.)

Snapshot of displaying the square root symbol so that the bar extends over the f.

FIGURE 17-9: Displaying the square root symbol so that the bar extends over the f.

To see how summation works, type TBox14 = annotation('textbox', [.45, .25, .15, .115], 'String', '$$\sum:{i=1}^{2n}{|k_i-k_j|}$$', 'BackgroundColor', [1, .5, .5], 'Interpreter', 'latex'); and press Enter. Notice the use of the double dollar signs in this case. In addition, be sure to include both the underscore and caret, as shown. Figure 17-10 shows the result of using this command.

Snapshot of showing a summation complete with upper and lower limits.

FIGURE 17-10: Showing a summation complete with upper and lower limits.

Integral

To display a definite integral, you use the LaTeX \int_{} function, along with the \d{} function for the slices. The \int_{} function accepts three inputs: two for the interval and the third for the function. In many respects, the format is the same as that used for summation. The beginning of the interval relies on the subscript underscore character, while the ending of the interval relies on the superscript caret character. You must enclose the entire command within double dollar signs ($$) or else the formatting of the superscript and subscript will fail.

To see how to create an integral, type TBox15 = annotation('textbox', [.61, .25, .22, .115], 'String', '$$\int_{y1(x)}^{y2(x)}{f(x,y)}\d{dx}\d{dy}$$', 'BackgroundColor', [1, .5, .5], 'Interpreter', 'latex'); and press Enter. Notice that the two slices come after the \int_{} function and that each slice appears in its own \d{} function. Figure 17-11 shows the result of this command.

Snapshot of defining a definite integral complete with interval.

FIGURE 17-11: Defining a definite integral complete with interval.

Derivative

When creating a derivative, you use LaTeX to define a combination of a fraction with superscripts. So, in reality, you’ve already created a derivative in the past — at least in parts. To see how a derivative works, type TBox16 = annotation('textbox', [.13, .17, .15, .085], 'String', '$\displaystyle\frac{d^2u}{dx^2}$', 'BackgroundColor', [1, .5, .5], 'Interpreter', 'latex'); and press Enter. Figure 17-12 shows the output from this command.

Snapshot of using a combination of fractions and superscripts to create a derivative.

FIGURE 17-12: Use a combination of fractions and superscripts to create a derivative.

Publishing Your MATLAB Data

At some point, you want to publish the information you create. Of course, most of the time, you don’t need to publish a matrix or other source data. What you want to publish are the plots you create from the data. You’ve heard the saying “a picture is worth a thousand words” a million times, and it still holds true. The following sections describe the techniques you use to output MATLAB data of any sort to other formats. However, the sections focus on plots, because that’s the kind of data you output most often. (If you want to discover the basics of how to publish functions and scripts, see the “Exporting scripts and functions” section of Chapter 16.)

Before you can work with the following sections, you need to ask MATLAB to generate some code for the plot that you defined in the previous sections of the chapter. If you already closed the figure that you created in the previous sections or you didn’t follow the steps, you can simply run the GeneratePlotFormatting.m script to generate the plot. Use the instructions in the upcoming “Saving your plot as a script” sidebar to save the resulting plot as a script named Bar1.m.

Performing advanced script and function publishing tasks

The publish() function can perform a number of different sorts of publishing tasks. The simplest way to publish a script or function is to call publish() with the name of the file. This approach produces an HTML file output. If you want to specify a particular kind of output, you provide the file format as the second input, such as publish('Bar1.m', 'pdf'). MATLAB supports the following output formats:

· .doc

· .html (default)

· .latex

· .pdf

· .ppt

· .xml

Tip After you finish publishing a script or function in HTML format, you can view it by using the web() function or double-clicking its entry in the Current Folder pane. To test this feature, first publish the Bar1.m script by typing publish('Bar1.m') and pressing Enter. After you see the success message, type web('html\Bar1.html') and press Enter. You see the MATLAB browser output, shown in Figure 17-13. However, even if this output looks perfect, always test the published output using the applications that your viewers will use to ensure that everything displays correctly.

Snapshot of displaying the results of the publication process using MATLAB's browser.

FIGURE 17-13: Display the results of the publication process using MATLAB’s browser.

SAVING YOUR PLOT AS A SCRIPT

You may need to save your plot as a script for later use without resorting to hand coding. MATLAB provides a method that creates a script for programmatically loading the plot in .fig form from disk. To perform this task, type saveas(Bar1, 'Bar1', 'm') and press Enter. In this case, you get a script for loading the plot from disk. In addition, MATLAB saves a copy of the plot for you. However, it saves just the plot because you used the Bar1 handle. If you want to save the entire figure instead, you must type saveas(gcf(), 'Figure 1', 'm') and press Enter (assuming that Figure 1 is indeed the current figure).

Another possibility is to use the GUI to create a function for your plot. To perform this task, choose File ⇒ Generate Code in the figure window. You see a message telling you that MATLAB is generating the code for you. When the message box disappears, the code is complete, and you see an editor window containing the resulting code. This technique creates a function to regenerate the entire figure. You can also click Edit Plot on the figure toolbar and then right-click individual elements. Choose Show Code from the context menu, and you see an editor window containing a function to generate just that element.

You can also use a version of publish() with name and value pair options. This version of publish() gives you the most control over the published output. You can control precisely where the document is saved as well as the size of any images provided with the output. Table 17-2 contains a list of the options and describes how you can use them.

TABLE 17-2 Using the publish() Options

Name

Values

Type

Description

catchError

true (default) or false

Code

Determines how MATLAB handles errors during the publishing process.

codeToEvaluate

String containing the required code

Code

Allows you to provide additional code with the published document so that it’s possible to perform tasks such as evaluating the code when the associated function requires inputs.

createThumbnail

true (default) or false

Figure

Determines whether the output document contains a thumbnail version of the full image (when an image is part of the output).

evalCode

true (default) or false

Code

Forces MATLAB to evaluate the code as it publishes the script or function, which results in additional details in the output file in some cases.

figureSnapMethod

entireGUIWindow (default), print, getframe, or entireFigureWindow

Figure

Defines the technique used to obtain the figure contained within the published document.

format

doc, html (default), latex, pdf, ppt, and xml

Output

Determines the format of the published document.

imageFormat

png, epsc2, jpg, bmp, tiff, eps, eps2, ill, meta, or pdf

Figure

Indicates the format of the figure contained within the published document. The default setting depends on the output document format. Some document formats won’t access all the format types. For example, PDF output is limited to the bmp or jpg options, but XML output can accept any of the file formats.

maxHeight

'' (default) or positive integer value

Figure

Determines the maximum height of the figure contained within the published document.

maxOutputLines

Inf (default) or non-negative integer value

Code

Specifies the number of lines of code that MATLAB includes in the published document. Setting this value to 0 means that no code is in the output.

maxWidth

'' (default) or positive integer value

Figure

Determines the maximum width of the figure contained within the published document.

outputDir

'' (default) or full path to output directory

Output

Specifies where to place the published document on disk.

showCode

true (default) or false

Code

Determines whether the published document contains any source code.

stylesheet

'' (default) or full path and XSL filename

Output

Specifies the location and name of an XSL file to use when generating XML file output.

useNewFigure

true (default) or false

Figure

Specifies that MATLAB is to create a new figure prior to publishing the document.

Saving your figures to disk

You must save your figures to disk if you want to use them the next session. However, saving a figure to disk can also help you publish the information in a form that lets others use the information as well. The format you choose determines how the saved information is used. Only the MATLAB figure (.fig) format provides an editable form that you can work with during the next session. The following sections describe the GUI and command method of saving figures to disk.

Using the GUI to save figures

To save an entire figure, choose File ⇒ Save As in the figure window. You see the Save As dialog box. Type a name for the file in the File Name field, select the format that you want to use to save the file in the Save As Type field, and click Save to complete the process.

Using commands to save figures

The command version of saving a figure depends on the saveas() command. To use this command, you supply a handle to the figure that you want to save as the first argument. The second argument is a filename. When you provide a type of file format to use as the third argument, the filename need not include a file extension. However, if you provide just the filename, you must provide an extension as well. MATLAB supports these file formats:

· .ai

· .bmp

· .emf

· .eps

· .fig

· .jpg

· .m

· .pbm

· .pcx

· .pdf

· .pgm

· .png

· .ppm

· .tif

Remember The handle that you provide need not be the figure itself. For example, if you type saveas(TBox1, 'TBox1.jpg') and press Enter, MATLAB still saves the entire figure. (Note that you have no way to specify that you want to save just a portion of the figure.)

Printing Your Work

Printing is one of the tasks that most people use the GUI to perform, even the most ardent keyboard user. The issue is one of convenience. Yes, you can use the printopt() and print() functions to perform the task using the keyboard, but only if you’re willing to perform the task nearly blind. The GUI actually shows you what the output will look like (or, at least, a close approximation). Using the commands is significantly harder in this case and isn’t discussed in the book. The following sections describe how to use the GUI to output your document.

Configuring the output page

Before you print your document, you need to tell MATLAB how to print it. Choose File ⇒ Print Preview in the figure window to display the Print Preview dialog box, shown in Figure 17-14.

Snapshot of configuring the page before you print it.

FIGURE 17-14: Configuring the page before you print it.

The right side of the dialog box shows an approximation of the changes you make on the left side. The settings are presented on four tabs with the following functions:

· Layout: Defines how the plot or other document will appear on the page. You specify the margins, size of the paper, and presentation of the information itself. The best way to work through the layout process is simply to try the settings and see how they affect the image shown in the right side of the dialog box.

· Lines/Text: Specifies the line widths and types of text used to print the documentation. In some cases, you find that using a different line weight or font for printing improves the output appearance of the document. Some of these settings are printer specific. For example, a built-in font is likely to provide a more pleasing appearance than a software font provided as part of the system.

· Color: Fixes the color changes between the display and the printer. What you see onscreen is unlikely to be what you get from the printer. The reasons for the difference are complex, but from an overview perspective, printers use subtractive color mixing, while displays use additive color mixing. The two kinds of color presentation don’t always work in sync with each other. Read the article at https://www.worqx.com/color/color_systems.htm for additional information.

· Advanced: Provides access to features such as recomputing the limits and ticks before printing. You won’t generally need these settings unless you notice a problem during the printing process.

Tip After you configure the plot for printing, you can print it immediately by clicking Print in the Print Preview dialog box.

Printing the data

After you create an output configuration, you can print the document. To perform this task, choose File ⇒ Print. You see the Print dialog box, in which you can choose a printer, configure it if necessary by clicking the Properties button, and then click OK to print the document.

Remember You don’t have to have direct access to the printer you want to use. The Print to File option in the Print dialog box lets you output the printed material to a file on disk. You can then send this file to the printer when you do have access to it. As an alternative, you can also send the file to someone else who needs the printed output (assuming that the person has access to the necessary printer).

If you find an error or have any questions, please email us at admin@erenow.org. Thank you!