MATLAB Lecture 8 School of Mathematical Sciences Xiamen Univer http://gdjpkc.xmu.edu.cn MATLAB Lecture 8-Graphics-Curve 绘图 Ref: MATLAB- Graphics- Basic Plotting Commands Vocabulary: plot绘图 轴 display显示 annotate注释 curve/ curved line曲线 explicit显式 implicit隐式 parameter参数 polar coordinates极坐标 boldface黑体 grid网格 tite标题 figure图形 legend图例 radian 弧度 radius半径 ● Some functions plot ezplot polar plot title xlabel ylabel *figure biplot grid on *grid off ● Graphics MATLAB provides a variety of functions for displaying vector data as line plots, as well as functions for annotating and printing these graphs t The representation of curve and surface The representation of curve on plane Explicit scheme y=f(x) Implicit formula: F(x, y)=0 x=x(1) Parameter representation Polar coordinates representation: p=f(e) Tabulation, say table of trigonometric function, experimental data etc Figure, say sine curve, experimental curve etc The representation of curve in space Explicit scheme: z=f(x,y) Implicit formula: F(x, y, z)=0 x=x(u, v) Parameter representation: y=y(u, v) (,v) Data form,x={x},y={y},z={n},=1,2,…,m,j=1,2,…,n
MATLAB Lecture 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec81 MATLAB Lecture 8 Graphics Curve 绘图 Ref: MATLAB→Graphics→Basic Plotting Commands l Vocabulary: plot 绘图 xaxis x 轴 display 显示 annotate 注释 curve/curved line 曲线 explicit 显式 implicit 隐式 parameter 参数 polar coordinates 极坐标 boldface 黑体 grid 网格 title 标题 figure 图形 legend 图例 radian 弧度 radius 半径 l Some functions plot ezplot polar plot3 title xlabel ylabel *figure *legend *subplot *grid on *grid off l Graphics MATLAB provides a variety of functions for displaying vector data as line plots, as well as functions for annotating and printing these graphs. ² The representation of curve and surface ¸ The representation of curve on plane Explicit scheme: y = f(x) Implicit formula: F(x,y) = 0 Parameter representation: ( ) ( ) x x t y y t Ï = Ì Ó = Polar coordinates representation: r = f (q ) Tabulation, say table of trigonometric function, experimental data etc. Figure, say sine curve, experimental curve etc. ¸ The representation of curve in space Explicit scheme: z = f(x,y) Implicit formula: F(x,y,z) = 0 Parameter representation: ( , ) ( , ) ( , ) x x u v y y u v z z u v Ï = Ô Ì = Ô = Ó Data form, { }, { }, { }, 1, 2,..., , 1, 2,..., i j ij x = x y = y z = z i = m j = n . Graphics
MATLAB Lecture 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn 2 Basic plotting Commands Plotting st The process of constructing a basic graph to meet your presentation graphics requirements is outlined in the following table. The table shows seven typical steps and some example code for each If you are performing analysis only, you may want to view various graphs just to explore your data. In this case, steps I and 3 may be all you need. If you are creating presentation graphics, you may want to fine-tune your graph by positioning it on the page, setting line styles and colors, adding annotations, and making other such Improvements I Typic 1. Prepare your data X=0:0.2:12 yl= bessel(l, x) 2. Select a window and position a plot figure(1) region within the window subplot(2, 2, 1) 3.Call elementary plotting function h=plot(x,yl, x,y2, x, y3); elect line and marker characteris- set(h Line Width, 2, 'Line Style"), ('",-,".) set(h, 'Color, f'r, g; b)) 5. Set axis limits, tick marks, and grid axis([0 12-0.]) grid 6. Annotate the graph with axis xlabel(Time,") labels. legend. and text ylabel('Amplitude legend(h, First, 'Second, Third) tle( Bessel Functions) yⅸx]=min(yl1) text(x(ix),y, First Min \ rightarrow Horizontalali 7. Export graph print-depsc-tiff-r200 myplot Plot plot(X, Y): plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up It can be used to plot of a curve expressed in explicit scheme or parameter 123456};y=[1-1.52-3-17] Lec8-2
MATLAB Lecture 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec82 ² Basic Plotting Commands ¸ Plotting Steps The process of constructing a basic graph to meet your presentation graphics requirements is outlined in the following table. The table shows seven typical steps and some example code for each. If you are performing analysis only, you may want to view various graphs just to explore your data. In this case, steps 1 and 3 may be all you need. If you are creating presentation graphics, you may want to finetune your graph by positioning it on the page, setting line styles and colors, adding annotations, and making other such improvements. Step Typical Code 1. Prepare your data x = 0:0.2:12; y1 = bessel(1,x); y2 = bessel(2,x); y3 = bessel(3,x); 2. Select a window and position a plot region within the window figure(1) subplot(2,2,1) 3. Call elementary plotting function h = plot(x,y1,x,y2,x,y3); 4. Select line and marker characteristics set(h,'LineWidth',2,{'LineStyle'},{'';':';'.'}) set(h,{'Color'},{'r';'g';'b'}) 5. Set axis limits, tick marks, and grid lines axis([0 12 0.5 1]) grid on 6. Annotate the graph with axis labels, legend, and text xlabel('Time') ylabel('Amplitude') legend(h,'First','Second','Third') title('Bessel Functions') [y,ix] = min(y1); text(x(ix),y,'First Min \rightarrow',... 'HorizontalAlignment','right') 7. Export graph print depsc tiff r200 myplot ¸ Plot function plot(X,Y): plots vector Y versus vector X. If X or Y is a matrix, then the vector is plotted versus the rows or columns of the matrix, whichever line up. It can be used to plot of a curve expressed in explicit scheme or parameter representation. >> x = [1 2 3 4 5 6]; y = [1 1.5 2 3 1 7]; >> plot(x, y);
MATLAB Lecture 8 School of Mathematical Sciences Xiamen Univer http:/gdjpkc.xmu.edu.cn File dit yiew Insert Tools Desktop Indos Help →日舀回长日国口 >a=16;149162536] ploa);% plot six lines(1,1)(2,4),(3,9);(4,16),(5,25);(6,36) Eile Edit Vie Insert Tools Desktop Window Help D日每令骨回日国回 Plot sin x over [0, 2T ]with title and grid >>t=0:pi/100:2°pi plot(t,y) > title( Plot of sinx vs x) %titled Plot of sinx vs x >xlabel('x #a'); ylabel('sinx) %adds text beside the X-axis Y-axis on the current axis grid on
MATLAB Lecture 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec83 >> a =[1:6; 1 4 9 16 25 36]; >> plot(a); %plot six lines (1, 1); (2, 4); (3, 9); (4, 16); (5, 25); (6, 36) Plotsin x over [0, 2p ] with title and grid. >> t = 0:pi/100:2*pi; >> y = sin(t); >> plot(t,y) >> title (‘Plot of sinx vs x’) %titled ‘Plot of sinx vs x’ >> xlabel(‘x 轴’); ylabel(‘sinx’) % adds text beside the Xaxis & Yaxis … on the current axis >> grid on
MATLAB Lecture 8 School of Mathematical Sciences Xiamen University http:/gdjpkc.xmu.edu.cn File Edit yiew Insert Tool: Desktop Lindow Help →日回长日国 一 Plot of sinx vsxytitle x轴)一a5 Plot the curve with x= asin mt, y=a cos nt over t E[0, 2T while a=8, m=2 and >t= linspace( 0, 2*pi); generates a row vector of 100 linearly equally spaced points between 0 and 2 T >X=a°sin(m*t); >y=a°cos(n°t) plot(x, y, 'b-7) color blue, line style"- FIgure 1 File Edit view Insert Tools Desktop Window Help y DG副舀心回|国| 10 10 Lec8-4
MATLAB Lecture 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec84 Plot the curve with x = a sin mt, y = a cos nt over t Œ[0, 2p ] while a=8, m=2 and n=5. >> t = linspace(0,2*pi); % generates a row vector of 100 linearly equally spaced… points between 0 and 2p . >> a=8; >> m=2; >> n=5; >> x = a*sin(m*t); >> y = a*cos(n*t); >> plot (x, y, ‘b’) % color blue, line style ‘’
MATLAB Lecture 8 School of Mathematical Sciences Xiamen Univer http://gdjpkc.xmu.edu.cn v Polar Plots polar(THETA, RHO)makes a plot using polar coordinates of the angle THETA,in radians versus the radius rho g=0.5 >> theta= linspace(0, 2*pi, 51) %generates 51 linearly equally spaced points polar(theta, gain, r-') %color red, line style solid title('\bf Gain versus angle \theta):%boldface, Theta will be display as 8 9Figure I Eile Edit Lie Insert Tools Desktop lindow Help theta Ezplot Function--Easy to use function plotter It is usually used to plot a curve expressed in implicit formula ezplot( FUn) plots the function FUN(X) over the default domain-2 pi<X<2 pi ezplot(FUN, [A, BD plots FUN(X)over A<X<B Plot the function x2-2x+1, over x∈[-2x,2丌 eplo(x^2-2*x+1) Figure 1 Edt互 N Insert o1s正 estep Rindos He D母↓间平日口
MATLAB Lecture 8 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec85 ¸ Polar Plots polar(THETA, RHO) makes a plot using polar coordinates of the angle THETA, in radians, versus the radius RHO. >> g=0.5; >> theta = linspace(0,2*pi,51); %generates 51 linearly equally spaced points… between 0 and 2p . >> gain = 2*g*(1+cos(theta)); >> polar (theta, gain, ‘r’) %color red, line style solid‘’ >> title (‘\bf Gain versus angle \theta’); %boldface, \theta will be display as q ¸ Ezplot Function Easy to use function plotter It is usually used to plot a curve expressed in implicit formula. ezplot(FUN) plots the function FUN(X) over the default domain 2*pi < X < 2*pi. ezplot (FUN,[A,B]) plots FUN(X) over A < X < B. Plot the function 2 x - 2x +1, over xŒ[-2p, 2p ]. >> ezplot('x^2 2*x + 1');