Академический Документы
Профессиональный Документы
Культура Документы
Basic Graphics
www.opencadd.com.br
Introduction to MATLAB
Basic Graphics - 2
Section Outline
2-D plotting
Graph Annotation
Subplots & Alternative Axes
3-D plotting
Specialized plotting routines
Patches & Images
Saving & Exporting Figures
Introduction to Handle Graphics
Copyright
Introduction to MATLAB
Basic Graphics - 3
2-D Plotting
Specify x-data and/or y-data
Specify color, line style and marker symbol
(Default values used if clmnot specified)
Syntax:
single line:
Plotting
plot(xdata, ydata,
'color_linestyle_marker')
Plotting
lines:x2,
plot(x1,multiple
y1, 'clm1',
Copyright
Introduction to MATLAB
Basic Graphics - 4
plot_2d
Copyright
Introduction to MATLAB
Basic Graphics - 5
Adding a Grid
grid on
Copyright
Introduction to MATLAB
Basic Graphics - 6
xx == 0:.1:2*pi;
0:.1:2*pi;
yy == sin(x);
sin(x);
plot(x,y,'b')
plot(x,y,'b')
grid
grid on
on
hold
hold on
on
plot(x,exp(-x),'r:*')
plot(x,exp(-x),'r:*')
addgraph
Copyright
Introduction to MATLAB
Basic Graphics - 7
Copyright
Introduction to MATLAB
Basic Graphics - 8
Graph Annotation
LEGEND
TITLE
TEXT
or
GTEXT
YLABEL
XLABEL
annotation
Copyright
Introduction to MATLAB
Basic Graphics - 9
Plot Editor
Add Text
Add Arrow
Add Line
Zoom In
Zoom Out
Rotate 3D
Introduction to MATLAB
Basic Graphics - 10
\bf
boldface
\it OR \sl
italics OR slanted
\rm
remove text formatting (normal)
Subscript _ or superscript ^:
Applies to next character or {text in curly braces}
Greek letters and Symbols (prefix with \):
Selected symbols, e.g. '\pi' =
latex_examp
Ref: Special characters using LaTeX
Copyright
Introduction to MATLAB
Basic Graphics - 11
sin(10t)
cos(10t)
Introduction to MATLAB
Basic Graphics - 12
Introduction to MATLAB
Basic Graphics - 13
Subplots
SUBPLOT- display multiple axes in the same figure window
subplot(#rows, #cols, index)
subplot(2,2,1);
subplot(2,2,1);
plot(1:10)
plot(1:10)
subplot(2,2,2)
subplot(2,2,2)
xx == 0:.1:2*pi;
0:.1:2*pi;
plot(x,sin(x))
plot(x,sin(x))
subplot(2,2,3)
subplot(2,2,3)
xx == 0:.1:2*pi;
0:.1:2*pi;
plot(x,exp(-x),r)
plot(x,exp(-x),r)
subplotex
subplot(2,2,4)
subplot(2,2,4)
plot(peaks)
plot(peaks)
Copyright
Introduction to MATLAB
Basic Graphics - 14
LOGLOG
Both axes
logarithmic
SEMILOGY
log Y
linear X
SEMILOGX
log X
linear Y
PLOTYY
2 sets of
linear axes
other_axes
Copyright
Introduction to MATLAB
Basic Graphics - 15
zz == 0:0.1:40;
0:0.1:40;
xx == cos(z);
cos(z);
yy == sin(z);
sin(z);
plot3(x,y,z)
plot3(x,y,z)
plot_3d
Ref: Color, Linestyle, Marker options
Copyright
Introduction to MATLAB
Basic Graphics - 16
surf_3d
Copyright
Introduction to MATLAB
Basic Graphics - 17
= e-x[sin(x)*cos(y)]
Introduction to MATLAB
Basic Graphics - 18
plot3d_soln
Copyright
Introduction to MATLAB
Basic Graphics - 19
spec_plots
Copyright
Introduction to MATLAB
Basic Graphics - 20
spec_plots2
Copyright
Introduction to MATLAB
Images
Basic Graphics - 21
aa == magic(4)
magic(4)
aa ==
Use Row 2
of colormap
for pixel (1,2)
16
16 22 33 13
13
55 11
11 10
10 88
99 77 66 12
12
44 14
14 15
15 11
image(a);
image(a);
map
map == hsv(16)
hsv(16)
map
map ==
1.0000
1.0000
00
1.0000
1.0000 0.3750
0.3750
1.0000
1.0000 0.7500
0.7500
00
00 Row 2
00 .....
.....
colormap(map)
colormap(map)
imagex
Copyright
Introduction to MATLAB
Basic Graphics - 22
Example: Images
load
load cape
cape
image(X)
image(X)
colormap(map)
colormap(map)
Copyright
Introduction to MATLAB
Basic Graphics - 23
Saving Figures
2 files created:
.m - text file
.mat - binary data file.
plot3d_soln
Copyright
Introduction to MATLAB
Basic Graphics - 24
Printing Figures
Introduction to MATLAB
Basic Graphics - 25
Exporting Figures
>>printdlg
Copying to Clipboard:
Copyright
Introduction to MATLAB
Basic Graphics - 26
Figure
Uicontrol
Image
Line
Axes
Patch
Surface
Uimenu
Text
Light
Copyright
Introduction to MATLAB
Basic Graphics - 27
Root
object
Figure
object
UIMenu
objects
UIControl
objects
Axes object
Surface
object
Line
objects
Text
objects
Copyright
Introduction to MATLAB
Basic Graphics - 28
2. Utility Functions
0 - root object handle
gcf - current figure handle
gca - current axis handle
gco - current object handle
3. FINDOBJ
h_obj = findobj(h_parent,
Copyright
Introduction to MATLAB
Basic Graphics - 29
addgraph
hh == findobj('Color',
findobj('Color', [0
[0 00 1])
1])
delete(h)
delete(h)
Copyright
Introduction to MATLAB
Basic Graphics - 30
Copyright
Introduction to MATLAB
Basic Graphics - 31
Object Browser:
Hierarchical list of
graphics objects
Property List:
List of properties &
current values for
selected object
propedit
Copyright
Introduction to MATLAB
Basic Graphics - 32
Copyright
Introduction to MATLAB
Basic Graphics - 33
Syntax:
set(ancestor,'Default<Object><Property>',<Property_Val>)
Use root object (0) to apply to all new
objects
Copyright
Introduction to MATLAB
Basic Graphics - 34
defaults
Introduction to MATLAB
Basic Graphics - 35
set(gcf,
set(gcf, 'DefaultSurfaceEdgeColor',
'DefaultSurfaceEdgeColor', 'factory')
'factory')
set(gcf,
set(gcf, 'DefaultSurfaceEdgeColor',
'DefaultSurfaceEdgeColor', 'remove')
'remove')
defaults
Copyright