Creating and Exporting Matlab Figures - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Creating and Exporting Matlab Figures

Description:

jr. Creating Matlab Figures. Editing axes and text objects ... jr. PowerPoint 'Dissolve' Example. opt = struct('format','png','width',5, ... – PowerPoint PPT presentation

Number of Views:2215
Avg rating:3.0/5.0
Slides: 22
Provided by: jordanro
Category:

less

Transcript and Presenter's Notes

Title: Creating and Exporting Matlab Figures


1
Creating and Exporting Matlab Figures
What you might not know, but should!
  • Jordan Rosenthal

2
Purpose
  • Introduce you to
  • commands
  • techniques
  • you may not have seen before.
  • Somewhat random in nature
  • Convince you it's easy to do (let's hope!)
  • Not so much a tutorial as it is a survey

3
Creating Matlab Figures
Matlab 5.3 (R11) Interactive features
  • Editing axes and text objects
  • Can change many properties without code
  • Run the following code

ezplot('cos(x)')
  • Change the line style and width
  • Change the axis title, x label, y label
  • Change fonts
  • Add a grid
  • Annotate
  • Etc.

4
Creating Matlab Figures
Useful functions available for download
suptitle.m puts a title above all subplots
sTitle 'a','b','c','d' for i 14
subplot(2,2,i) imagesc(rand(16)) title(
sTitlei ) end pause suptitle('Main title')
5
Creating Matlab Figures
Useful functions available for download
arrow.m add an arrow to a plot
arrow demo
arrow demo2
clf axis(-5 5 -5 5) arrow(-4 -3,2 3)
6
Creating Matlab Figures
Adding LaTeX-like symbols to a plot
clf h remez(30,0 0.4 0.6 1,1 1 0 0) H,w
freqz(h) plot( w/pi, abs(H) ) title('
H(ej\omega) ') xlabel('\omega / \pi')
Only a subset of LaTeX supported, but still useful
7
Creating Matlab Figures
Using FILL to create polygons
clf ang 2pi/6 ( 0 5 ) r
ones(1,6) x,y pol2cart(ang,r) fill(x,y,'r',
'EdgeColor','k','LineWidth',3) axis(-2 2 -2
2) axis equal view(3)
8
Creating Matlab Figures
EASY to use lighting and visualization commands
figure('Pos',550 350 560 420) surf(peaks)
axis tight pause camlight headlight
pause shading interp
pause lighting phong
pause material metal
pause material shiny
pause colorbar
pause colormenu
9
Creating Matlab Figures
How to save on ink (this plot still needs a
little work)
cla colormap(jet) h fspecial('average',7) H,
w1,w2 freqz2(h) surfl(w1,w2,abs(H),'light') sh
ading interp lighting phong colorbar
colormap(gray) pause colormap(1-gra
y)
colormap( 1-rgb2gray(jet) ) pause brighten(0.5)
pause material dull
10
Export Problems
Problems when exporting to documents
11
Export Example 1
x 0 0.1 20 y sin(x) plot(x,y) axis(0
20 -2 2) grid on
1)
2)
Adjust aspect ratio
cd z\Staff\jr\MatlabPres print -deps2
example1.eps
3)
Show example1.eps in GhostView
4)
Wrong aspect ratio
12
Export Example 1
Usual Solution
Scale plot in document
squashed fonts
A better way
exportfig(gcf,'example1a.eps','width',6,... 'font
mode','fixed','fontsize',10)
Show example1a.eps
13
Export Example 2
x 0 0.1 20 y1 sin(x) y2
cos(x) plot(x,y1,x,y2) legend('sin','cos') axis
(0 20 -2 2) grid on title('Plot of sin and
cos')
1)
2)
Adjust aspect ratio (note colors)
exportfig(gcf,'example2.eps', ...
'linestylemap','bw')
3)
4)
Show example2.eps
14
ExportFig Features
Everything you want from PRINT and more
  • Can set session defaults
  • Can change height, width, or both
  • Can change color space
  • Can lock axes limits and ticks before export
  • Fonts can scale with size or be fixed to a point
    size
  • Can use 'latin1' or 'adobe' character encoding
  • Line widths can be fixed or scaled and min/max
    widths can be set
  • Line style can be automatically mapped or mapped
    according to user preferences
  • Can separate text into its own eps file
  • e.g., use bitmap image and overlay vectorized text

15
Helper Files
  • PREVIEWFIG
  • Preview a figure before exporting
  • APPLYTOFIG
  • Apply export options to a figure
  • RESTOREFIG
  • Restore figure to previous state

16
Importing into LaTeX
"Using Imported Graphics in LaTeX
2?" epslatex.ps, http//www.ctan.org
Everything you need to know
  • \usepackagegraphicx
  • ...
  • \beginfigure
  • \centering
  • \includegraphicsmyfig.eps
  • \captionThe figure caption
  • \labelfigCoolFigure
  • \endfigure

17
Importing into PowerPoint
  • PowerPoint does not support EPS
  • Can only display EPS files with a raster preview,
    typically TIFF
  • large files, sometimes causing memory problems
  • Use PNG, JPEG instead
  • Sometimes Matlab's Export menu works fine for
    this
  • Use EXPORTFIG
  • Yes, usually this means one file for visual
    presentation and one for written paper

18
PowerPoint "Dissolve" Example
19
PowerPoint "Dissolve" Example
opt struct('format','png','width',5,
... 'fontmode','fixed','fontsize',10,
... 'color','rgb') surf(peaks) exportfig(gcf,'
example3a.png',opt) shading interp exportfig(gc
f,'example3b.png',opt) camlight headlight
lighting phong exportfig(gcf,'example3c.png',opt)

20
PowerPoint "Dissolve" Example
Creating the dissolve
  • Insert --gt Picture --gt From File(PNGs were 10-30
    kB)(EPS with TIFF were 340-2500 kB!)
  • Place on top of each other
  • Slide Show --gt Custom Animaton
  • Animate pictures on mouse click
  • Set effect to "dissolve"

21
References
  • Matlab command help
  • ezplot, fill, surf, camlight, lightangle,
    shading, lighting, material, colorbar, colormap,
    brighten
  • User contributed files
  • http//www.mathworks.com/support/ftp/graphicsv5.sh
    tml
  • suptitle.m, arrow.m
  • Matlab Digest Articles
  • Part I(http//www.mathworks.com/company/digest/ju
    ne00/export/)
  • Part II(http//www.mathworks.com/company/digest/d
    ecember00/export.shtml)
  • exportfig.m (updated), previewfig.m,
    applytofig.m, restorefig.m
Write a Comment
User Comments (0)
About PowerShow.com