Download presentation
Presentation is loading. Please wait.
Published byOscar Fletcher Modified over 9 years ago
1
1 Advanced Plotting ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem http://www.cpe.ku.ac.th/~anan anan@cpe.ku.ac.th
2
2 Outline xy plot Grid and Axis fplot polynomial plot subplot
3
3 Plotting Two-dimensional plot (xy plot) help graph2d Three-dimensional plot (xyz plot, surface plot) help graph3d
4
4 xy Plotting Functions y = f(x) x-axis (abscissa) y-axis (ordinate) abscissa ordinate
5
5 The Anatomy of a Plot Plot TitleY-Axis Label X-Axis Label Tick Mark Tick-Mark Label Legend Data Symbol
6
6 Plot Essential Features Axis label with unit Regular spaced tick mark (0.5, 1.0, 1.5, … ) More than one curve use Legend Use Title Plot measured data using Data Symbol Careful about connecting line
7
7 Plotting example y = 0.4 √1.8x for 0 ≤x ≤ 52 y = height of a rocket after launch (miles) x = horizontal (downrange) distance (miles) >>x = [0:0.1:52]; >>y = 0.4*sqrt(1.8*x); >>plot(x,y) >>xlabel(’Distance (miles)’) >>ylabel(’Height (miles)’) >>title(’Rocket Height as a Function of Downrange Distance’)
8
8 Plotting example
9
9 Grid and axis Commands grid display gridlines toggle by grid on or grid off axis override MATLAB axis syntax axis([xmin xmax ymin ymax])
10
10 Plotting example II >>x = [0:0.1:52]; >>y = 0.4*sqrt(1.8*x); >>plot(x,y) >>xlabel(’Distance (miles)’) >>ylabel(’Height (miles)’) >>title(’Rocket Height as a Function of Downrange Distance’) >>grid on >>axis([0 52 0 5])
11
11 Plotting example II
12
12 Plots of Complex Numbers plot(y) plot(real(y),imag(y)) >>z = 0.1 + 0.9i; >>n = [0:0.01:10]; >>plot(z.^n) >>xlabel(‘Real’), ylabel(‘Imaginary’)
13
13 Plots of Complex Numbers
14
14 fplot command Automatically analyzes the function Then decides the plotting points Syntax fplot(‘string’,[xmin xmax]) string describe function [xmin xmax] value of variable
15
15 fplot example >>a_func = ‘cos(tax(x))-tan(sin(x))’; >>fplot(a_func,[1 2]) >>xlabel(‘x’),ylabel(‘function’) >>title(‘using fplot’)
16
16 fplot example I
17
17 Compare to fplot >>x=[1:0.01:2]; >>y=cos(tax(x))-tan(sin(x)); >>plot(x,y) >>xlabel(‘x’),ylabel(‘function’) >>title(‘using fplot’)
18
18 Compare to fplot
19
19 Compare to fplot fplot plot
20
20 Polynomial Plot >>x=[-6:0.01:6]; >>p=[3,2,-100,2,-7,90]; >>plot(x,polyval(p,x)) >>xlabel(‘x’),ylabel(‘p’) >>title(‘polynomial plot’) p(x) = 3x 5 + 2x 4 – 100x 3 +2x 2 – 7x+90
21
21 Polynomial Plot
22
22 Subplots Several smaller plots in one figure Syntax subplot(m,n,p) m m rows n n columns p output plot
23
23 Subplots example I >> x = [0:0.01:5]; >>y = exp(-1.2*x).*sin(10*x+5); >>subplot(1,2,1) >>plot(x,y),axis([0 5 -1 1]) >>x = [-6:0.01:6]; >>y = abs(x.^3-100); >>subplot(1,2,2) >>plot(x,y),axis([-6 6 0 350]) y = e -1.2x sin(10x + 5) for 0 ≤x ≤ 5 y = |x 3 - 100| for -6 ≤ x ≤ 6.
24
24 Subplots example I
25
25 Subplots example II >> x = [0:0.01:5]; >>y = exp(-1.2*x).*sin(10*x+5); >>subplot(2,1,1) >>plot(x,y),axis([0 5 -1 1]) >>title(‘figure(a)’) >>x = [-6:0.01:6]; >>y = abs(x.^3-100); >>subplot(2,2,2) >>plot(x,y),axis([-6 6 0 350]) >>title(‘figure(b)’)
26
26 Subplots example II
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.