Introduction to Matlab - to be used in conjunction with some book or article of more substance, e.g. the student edition of Matlab, or the Matlab Primer How to plot data in MATLAB (for your information; work through this, but do not hand it in.) To display 2-dimensional data in MATLAB, use the function plot(), whose argument needs to be a vector. MATLAB does not do symbolic math, so a command like plot(sin(t)) makes no sense unless MATLAB knows what "t" is (It does have its own algorithms for sine, cosine, etc. ). Proceed thusly to graph the sine function on the interval [0,4*pi] using 125 equally spaced points (enter the commands as written to the right of the MATLAB prompt >>): >>t = 0:4*pi/125:4*pi This creates a vector named t with entries [0,4*pi/125,8*pi/125,...,4*pi] Notice that this entire list of numbers was displayed on the screen, which is not generally what you want. To SUPPRESS the display, end the line with a semi-colon(;)! >> x = sin(t); This creates a vector named x with entries [sin(0),sin(4*pi/125),...,sin(4*pi)] >>plot(x) Notice the units... >>plot(t,x) What's the difference? >>y = sin(t+.25); Phase shift >>z = sin(t+.5); Another >>hold on The next graph drawn will not erase the present one. >>plot(t,y,'--') >>plot(t,z,'.') >>title('sine function with phase shift') >>xlabel('t') >>ylabel('sin(t+)') Self-explanatory >>hold off >>plot(x,z) What is this? >>subplot(3,1,1), plot(x) >>subplot(3,1,2), plot(y) >>subplot(3,1,3), plot(z) Subplot(m,n,p) creates an m by n array of plots on a single screen, and refers to the pth one, counting from the upper left. Experiment with this a bit, till you're sure how it works. To get a printout from MATLAB: >>print -dps2 Sends whatever's displayed to the printer; once something's gone from the screen, it can't be printed. The -dps2 makes it print faster; just plain "print" will also work. >>print -dps2 filename.ps Command to save the current image as a text file with the name "filename.ps". At some later time, this can be sent to the printer by using the command %lp filename.ps (this command is issued from outside MATLAB, in a cmdtool window.) VERY IMPORTANT!! MATLAB has an extremely useful "help" facility. If you don't know how the print command works, do >>help print and similarly for everything else. In the next section, you may want to type help eul at some point.... Before beginning the next section, do >>subplot(1,1,1) to get back to a single figure. There are other ways to do this, including >>clf To save your favorite variable(s) so that they'll be available to you the next time: >>save myfile x y z saves x, y, and z in a file named myfile.mat To leave Matlab, >>quit To LOAD the file myfile.mat, %matlab >>load myfile Last but not least, YOU CAN RECALL AND EDIT THE PREVIOUS COMMANDS. This means you do not have to type in a complicated expression more than once. The commands are (try them out). ctrl-p (hold down the control key and then press p) displays the previous command. Doing it twice displays the "next" previous command. ctrl-n the next command in case you went back too far. Once you've got the line you want on the screen, you can edit it by doing ctrl-b non-destructive backspace ctrl-f forward one character ctrl-d delete the character under the cursor backspace delete the character to the left of the cursor ctrl-a beginning of the line ctrl-e end of the line ctrl-k erase everything to the right of the cursor That should be enough to get you going.......You'll learn more as you proceed through the labs. Be aware that Matlab is a professional research tool, used daily by thousands of working scientists. It will be a useful addition to your collection of skills to become proficient in its use. NOTE: As a last resort, there's a user's guide and a reference manual on the table near the door to the lab. Please refrain from stealing them. As a next-to-the-last resort, you can purchase the Student Edition of Matlab at one of the bookstores. You can either get a DOS version (that requires Windows) or a Macintosh version. Retail price (as of this writing) is about $65-70. Be sure to get the 4.x (instead of 3.5x) version. This has a rather useful manual, and the Matlab software (slightly limited in that it will only handle 90x90 matrices, but for most people, that's plenty) which includes the Maple symbolic toolbox. It's a pretty good deal, in my opinion, particularly compared to the comparable deals for Mathematica.