Colours Line Styles/symbolsy yellow . pointm magenta o circlec cyan x x-markr red + plusg green - solidb blue * starw white : dottedk black -. dashdot-- dashedThe number of available plot symbols is widerthan shown in this table. Use help plot toobtain a full list. See also help shapes.The command clf clears the current figure whileclose(1) will close the graphics window labelled“Figure 1”. To open a new figure windowtype figure or, to get a window labelled“Figure 9”, for instance, type figure (9). If“Figure 9” already exists, this command willbring this window to the foreground and thenext plotting commands will be drawn on it.13.4 Multi–plotsSeveral graphs may be drawn on the same figureas in>> plot(x,y,’k-’,x,cos(3*pi*x),’g--’)A descriptive legend may be included with>> legend(’Sin curve’,’Cos curve’)which will give a list of line–styles, as they appearin the plot command, followed by the briefdescription provided in the command.For further information do help plot etc.The result of the commands>> plot(x,y,’k-’,x,cos(3*pi*x),’g--’)>> legend(’Sin curve’,’Cos curve’)>> title(’Multi-plot’)>> xlabel(’x axis’), ylabel(’y axis’)>> gridis shown in Fig. 3. The legend may be movedeither manually by dragging it with the mouseor as described in help legend.Fig. 3: Graph of y =sin3⇡x and y = cos 3⇡xfor 0 apple x apple 1 using h =0.01.13.5 HoldA call to plot clears the graphics window beforeplotting the current graph. This is not convenientif we wish to add further graphics to thefigure at some later stage. To stop the windowbeing cleared:>> plot(x,y,’r-’), hold on>> plot(x,y,’gx’), hold off“hold on” holds the current picture; “hold off”releases it (but does not clear the window, whichcan be done with clf). “hold” on its own togglesthe hold state.13.6 Hard CopyTo obtain a printed copy select Print from theFile menu on the Figure toolbar.Alternatively one can save a figure to a file forlater printing (or editing). A number of formatsis available (use help print to obtain alist). To save the current figure in “EncapsulatedColor PostScript” format, issue the Matlabcommandprint -depsc fig1which will save a copy of the image in a filecalled fig1.eps.print -f4 -djpeg90 figbwill save figure 4 as a jpeg file figb.jpg at aquality level of 90. It should be borne in mindthat neither command (despite its name) sendsthe file to a printer.13
13.7 SubplotThe graphics window may be split into an m⇥narray of smaller windows into each of which wemay plot one or more graphs. The windowsare counted 1 to mn row–wise, starting fromthe top left. Both hold and grid work on thecurrent subplot.>> subplot(221), plot(x,y)>> xlabel(’x’),ylabel(’sin 3 pi x’)>> subplot(222), plot(x,cos(3*pi*x))>> xlabel(’x’),ylabel(’cos 3 pi x’)>> subplot(223), plot(x,sin(6*pi*x))>> xlabel(’x’),ylabel(’sin 6 pi x’)>> subplot(224), plot(x,cos(6*pi*x))>> xlabel(’x’),ylabel(’cos 6 pi x’)subplot(221) (or subplot(2,2,1)) specifiesthat the window should be split into a 2 ⇥ 2array and we select the first subwindow.13.8 ZoomingWe often need to “zoom in” on some portionof a plot in order to see more detail. Clickingon the “Zoom in” or “Zoom out” button on theFigure window is simplest but one can also usethe command>> zoomPointing the mouse to the relevant position onthe plot and clicking the left mouse button willzoom in by a factor of two. This may be repeatedto any desired level.Clicking the right mouse button will zoom outby a factor of two.Holding down the left mouse button and draggingthe mouse will cause a rectangle to be outlined.Releasing the button causes the contentsof the rectangle to fill the window.zoom off turns o↵ the zoom capability.Exercise 13.1 Draw graphs of the functionsy = cos xy = xfor 0 apple x apple 2 on the same window. Use thezoom facility to determine the point of intersectionof the two curves (and, hence, the rootof x = cos x) to two significant figures.13.9 Figure PropertiesAll plot properties can be edited from the Figurewindow by selecting the Edit and Toolsmenus from the toolbar. For instance, to changethe linewidth of a graph, click Edit and chooseFigure Properties... from the menu. Clickingon the required curve will display its attributeswhich can be readily modified.One of the shortcomings of editing the figurewindow in this way is the di culty of reproducingthe results at a later date. The recommendedalternative involves using commandsthat directly control the graphics properties.The current setting of any plot property can bedetermined by first obtaining its “handle number”,which is simply a real number that wesave to a named variable:>> plt = plot (x,y.^3,’k--o’)plt =188.0194and then using the get command. This lists thesettings for a number of properties that include>>get(plt)Color: [0 0 0]LineStyle: ’--’LineWidth: 1Marker:’o’MarkerSize: 6XData: [1 2 3]14
- Page 1 and 2: An Introduction to MatlabVersion 3.
- Page 3 and 4: 1 MATLAB• Matlab is an interactiv
- Page 5: These are not allowable:Net-Cost, 2
- Page 8 and 9: Note that the components of x were
- Page 10 and 11: For example, if u = [10, 11, 12], v
- Page 12 and 13: a.*b -24, ans./cans =-18 -10 0 12 2
- Page 16 and 17: YData: [27 8 1]ZData:[1x0 double]Th
- Page 18 and 19: 14 Elementwise ExamplesExample 14.1
- Page 20 and 21: 0 00 0The second command illustrate
- Page 22 and 23: 9 10 11 1220 0 5 4>> J(1,1)ans =1>>
- Page 24 and 25: 15.12 Sparse MatricesMatlab has pow
- Page 26 and 27: It is well-known that the solution
- Page 28 and 29: the corresponding number, and two f
- Page 30 and 31: -2.0000 3.1416 5.0000-5.0000 -3.000
- Page 32 and 33: if logical test 1Commands to be exe
- Page 34 and 35: 6 8 0 1>> k = find(A==0)k =29Thus,
- Page 36 and 37: function [A] = area2(a,b,c)% Comput
- Page 38 and 39: In order to plot this we have to de
- Page 40 and 41: 100 2256200 4564300 3653400 6798500
- Page 42 and 43: ’string’,’lin-log’,...’po
- Page 44 and 45: Matrix analysis.cond Matrix conditi
- Page 46 and 47: imag, 42inner product, 8, 21, 22int