Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

 

Newsletters - MATLAB News & Notes

MATLAB Tips & Tricks:
Printing and Exporting Graphics

Tech Support answers three frequently asked questions

by Rob Monteiro












Welcome to MATLAB Tips & Tricks, a column devoted to answering the most commonly asked questions received by The MathWorks technical support team. In this edition of News & Notes , we discuss the intricacies our customers encounter the most when attempting to print or export graphics from MATLAB.

How can I use device options such as PostScript and Ghostscript and still specify the printer?


There are a couple of ways to do this. On UNIX, the most common way is to use the -P flag, which allows you to specify a printer. You can use this flag in combination with a Ghostscript or PostScript driver. For example, this command will print to a printer named Nike in Postscript format:

print -PNike -dps

On Windows, there is an option, -v, that allows the Print dialog box to open. Again, this can be used in conjunction with any device drivers. For example,

print-v -dwinc

allows you to choose a printer through the dialog box (the same dialog box that opens when you pull down the File menu and select Print) using the -dwinc driver. This command is most useful in GUI applications where the designer wants you to have flexibility in choosing a printer but to use a specific driver that MATLAB provides. For MATLAB 5.2 and earlier, please refer to the manual Using MATLAB Graphics for information on capturing printer ports. Please note that in MATLAB 5.3 (to be released in the future), the process of capturing ports will be much easier, as MATLAB will recognize your default Windows printers.

How can I avoid segmentation violations, bus errors, floating point exceptions, and illegal instructions when printing?


These error messages are usually the result of an incompatibility between MATLAB and a printer driver. They occur when MATLAB detects a memory fault because of an unexpected modification that some printer drivers make to the floating-point unit (FPU) of the computer. Several of our customers have reported that this particular behavior of the printer driver causes similar problems in other prominent software products, such as Maple, Scientific Word, and Mathcad. As possible workarounds, you can try the following:

  • If you have a Postscript compatible printer, use one of the MATLAB PostScript drivers to print. For example, print -dps will print to the default printer in level 1 PostScript.
  • Use a built-in Ghostscript device that is compatible with the printer you are using. For example, if your default printer is an HP Laserjet III, you can try print -dljet3, which will print to that printer with the Ghostscript driver. To see a complete list of device drivers built into MATLAB, type help print at the MATLAB command prompt.
  • Use other printer drivers that are compatible with the printer. You can obtain them from the printer manufacturer.
  • Import the figure to another application and print it from that application. Our development staff is aware of the limitations and the incompatibilities that exist with certain printer drivers. In MATLAB 5.2, we have implemented an internal procedure that detects the printer driver's modification of the FPU and restores the state of the FPU to its previous setting. This procedure should eliminate this problem.

How do I import MATLAB graphics into Microsoft Office 97?


These tips are tailored towards Microsoft Word. Most will also work for PowerPoint, but some of the actions specific to importing figures may be different.

The most common way of exporting MATLAB graphics on the PC is to go to the Figure window, select the Edit menu, and choose Copy. This will send the figure into the Windows clipboard as an enhanced metafile. Then, in the appropriate part of the Word document, pull down the Edit menu and choose Paste.

You may want to perform this function in an M-file or in a callback for a GUI directly from the command line. This can be done with the command

print -dmeta

This command will put the current figure into the clipboard as an enhanced metafile (EMF). You can then paste the figure into Word as noted above.

Because of a bug in Office 97 on the Windows 95 platform (see Microsoft Knowledge Base Article ID# Q158889), MATLAB graphics exported to Office 97 will not always print properly. We suggest importing figures into Word using the following alternatives:

• Use Z-Buffer rendering when creating your EMF file. First generate your plot, then type

print -zbuffer -dmeta

[or]

print -zbuffer -dmeta filename

  • Convert your EMF file to Word objects. First generate your plot, copy and paste the figure it into Word, and then double-click on the picture.
  • Paste the MATLAB figure in the Windows metafile format (WMF). First generate your plot and then copy the figure. In Word, select Edit-Paste Special, and then select Picture.
  • Use a bitmap instead of a metafile. First select the File-Preferences menu in the MATLAB command window. Second, choose Copying Options, and then select Windows Bitmap or simply type print -dbitmap in the MATLAB command window.
  • Create a PostScript file rather than a metafile. If you have a PostScript compatible printer, import your MATLAB figure as an EPS file. In MATLAB, type

print -deps filename

In Word, select the Insert menu, and then choose Picture. In the next submenu, choose From File and Browse until you find filename.eps. Then, print your Word document to a PostScript printer using a PostScript printer driver. MATLAB 5.1 provides the capability of adding a tiff preview to this file. However, in MATLAB 5.0 and earlier, there is no way to add a preview to EPS files, so you will only see a bounding box when you import into Word. To generate the preview with the EPS file, use the following syntax:

print -deps filename -tiff

Then, import the figure into Word by using the method described above.

Tech Support

To access the Tech Support area on the Web and search the same database that our technical support engineers use, visit www.mathworks.com and select Tech Support Solution Search.

Contact sales
E-mail this page
Print this page
Subscribe to newsletters