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-2MATLAB 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);