SavingGraphics - CSC 113: Saving Plots and Graphics in...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSC 113: Saving Plots and Graphics in Matlab This document covers the basics of saving a figure created in MATLAB, so that it may be used in some other setting, such as a web page, written report, or overhead presentation. First, lets create a figure. The following script will plot the fourth- and fifth-order Chebyshev polynomials for a range of input values: % % Simple plot script % % Create range of x values and their squares: % xx = linspace(-1.1,1.1,200); xx2 = xx . * xx; % % Chevyshev polynomials of orders 4 and 5: % % T 4(x) = 8 x4 - 8 x2 + 1 % T 5(x) = 16 x5 - 20 x3 + 5 x % T4 = (8 * xx2 - 8) . * xx2 + 1; T5 = ((16 * xx2 -20) . * xx2 + 5) . * xx; figure(1); plot(xx,T4,linewidth,2); axis([-1.1 1.1 -5 5]); hold on plot(xx,T5,r,linewidth,2); % % Draw a dashed square box, % to highlight the equi-ripple region of the % Chebyshev polynomials: % xpath = [-1 -1 1 1 -1]; ypath = [-1 1 1 -1 -1]; plot(xpath,ypath,-.); hold off xlabel(Input argument); ylabel(Function value); legend(T 4(x), T 5(x),Location,SouthEast); This should bring up a figure window as in figure 1 . One is tempted to use the File Save menu item; this creates a figure file with the .fig extension that is useful for opening the figure in a later MATLAB session. Unfortunately, the *.fig format is only readable by MATLAB, so other programs cant use it. 1 Figure 1: Figure window produced from the example script. One approach to saving the figure is to use any screen capture program, to perform a screen dump of the figure window into a graphic file. (This is how figure 1 was obtained.) The resulting image quality, however, is limited by the screen resolution, and likewise includes other elements (such as the tool bars and window decorations) which distract from the plot itself. Fortunately, MATLAB provides the print command to save the contents of a plotting window as a graphic file. (The command name print is a hangover from the early days before graphic computer terminals, when a plot was obtained by sending data points to a line printer.) Well examine the following commands: >> print -dpng figplot.png >> print -djpeg figplot.jpg >> print -dtiff figplot.tiff >> print -depsc2 figplot.eps This will create four files, each a different format. (Only one of these commands will be necessary in practice, depending on the desired image format.) The different formats are reviewed in turn: Portable Network Graphics (.png) The -dpng option after the print command tells MATLAB to use the png driver, and name...
View Full Document

Page1 / 6

SavingGraphics - CSC 113: Saving Plots and Graphics in...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online