DOC PREVIEW
MIT 13 42 - HELPFUL MATLAB PLOTTING COMMANDS

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

13.42:HELPFUL MATLAB PLOTTING COMMANDSc°A.H. TECHETMATLAB will be a useful tool to know throughout the course of the semester. The first homeworkcan be simplified using MATLAB and the first lab will ask each lab group to use MATLAB priorto the lab session to generate a waveform to study. Throughout the term there may be otherassignments which call for the use of a software package such as MATLAB. The specific use ofMATLAB is not required.Running MATLAB on Athena is quite simple. At a workstation you can use the softwarepull-down menus at the top of the screen or at an Athena prompt type add matlab press return,then matlab.There are some common functions that are used frequently in MATLAB. Several of these arelisted below with descriptions of their use. If you are looking for a certain function and want toknow how to use it type help command at the prompt, replacing “command” with the functionname. It is also useful to look at the “Using MATLAB” manual that ships with the PC version ofMATLAB if you have access to one. There will be a copy available at each of the lab sessions inthe Towtank. Mathworks has extensive information on their web site about the functions and usingMATLAB http://www.mathworks.com. If a problem requires complex MATLAB code, a guidelinewill be included in the homework. If you choose to use a program other than MATLAB that is fine.In MATLAB it is simple to create a script that p erforms a series of commands similar to a C orFORTRAN code. Edit a file with a ∗.m extension in the working directory. Type commands in orderyou wish them performed and save the file. Note: a script is different from a MATLAB function inthat variables defined and calculated in a script are global, but within a function variables are onlylocal unless passed in and out (help function).who: lists all variables in the MATLAB workspace. Another option is whos, which is similarin effect to ‘ls − l’ in UNIX, lists the variables and their size. To look at the contents of avariable just type the variable name at the MATLAB prompt omitting the semicolon at theend of a line.cd dir: changes to the desired directory, where your script is located, unless you include theworking directory in the path you must be in the correct directory to run a function orscript.path: displays all the directories that MATLAB searches in for the functions called. If yourfunction is not in one of these directories you must change to that directory before calling afunction.figure(1): make figure 1 the current plot; future plotting commands will be directed into thewindow for figure 1. This is useful when you have multiple figure windows open and want ascript to plot in a window different from the current figure. Call the figure(#) commandbefore the plot command.subplot(3,1,2): breaks the current figure window into a three by one array of distinct plottingregions and sets the current region to be the second of the three. You can change thecurrent region with something like subplot(3,1,3). Can also type subplot 312 droppingthe brackets and commas. subplot 324 will make a figure with three rows and two columns12c°A.H. TECHETof plots (six total), the third number refers to which of the six plots will be made active.Counting is from left to right, top to bottom.hold: hold the current contents of the active figure; this means that any subsequent plotcommands will draw on top of whatever is already there rather than starting from scratch.A second hold command will release the figure. It is also possible to type hold on andhold off to toggle the hold state.clf: clears the current figure window. Also removes any hold and/or subplot sectioning. Thisdoes not toggle the hold command– if hold is on it will stay on.plot(x1, y1, ‘-’, x2, y2, ‘–’, x3, y3, ‘:’): plot three curves defined by the xiand yivectors,each with a different line style (in this case, solid, dashed, and dotted). The text argumentsafter the y vector for each curve can also be used to define marker style (circle, x, *, etc.)and curve color. Type help plot for a list of color and marker codes.legend(‘curve 1’, ‘curve 2’, ‘curve 3’): assign and draw the legend for curves 1 (the solidline), etc. You can click on the legend with the mouse and move it around once it has beendrawn.axis([xmin, xmax, ymin, ymax]): change the limits on the plot axes. V = axis will returnthe axis limits for the current figure.xlabel(‘time (s)’): set the label on the x axis of the current graph (and current suplot if ap-plicable) to the given text. Same holds true for ylabel(‘H (m)’). Certain greek symbols canbe used in plots, such as ω by typing similar commands used in LaTeX. xlabel(‘\ omega’)for example.gtext(‘message text’): allows you to place the text given in the argument onto a graph usingthe mouse. Helpful for labeling the interesting features of any given plot.ginput: allows you to click on points in the graph with the mouse. When you hit return youwill leave input mode and the x and y coordinates for the points that you clicked on willbe displayed. To record the values you click type [x, y] = ginput(2); for two values (anyinteger number will work).zoom: toggles the ability to zoom in or out on the current graph. When zooming, clicking onthe left mouse button zooms you in around the point you clicked on; clicking on the rightbutton zooms you out. zoom on; zoom off.orient tall: set the orientation of the printed version of the plot to be full page portrait. Otheroptions are portrait (the default) and landscape.print -deps filename.eps: send the current figure to the file filename.eps using the currentpage orientation. There are other formats you can use– listed under help print.[p,f] = spectrum(x, 512, 0, [], 200): generate a power spectrum for the data in vector x,using 512 point FFT’s, with no overlap between windows, the default Hanning window andgiven that the sampling rate was 200 Hz. In general increasing the size of your FFTs willincrease the resolution of your spectrum (the number of points for which you actually getinformation back); it will not increase the maximum frequency for which you get informationback. That is controlled by the Nyquist frequency which is defined as one-half of your samplerate. Having FFTs longer than the length of x does not make sense and you should makethem small enough such that several windows will actually slide along x so that you will getgood averaging. It’s traditional (and


View Full Document

MIT 13 42 - HELPFUL MATLAB PLOTTING COMMANDS

Download HELPFUL MATLAB PLOTTING COMMANDS
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view HELPFUL MATLAB PLOTTING COMMANDS and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view HELPFUL MATLAB PLOTTING COMMANDS 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?