This action might not be possible to undo. Are you sure you want to continue?
Joseph C. Slater Jason J. Blair January 3, 1997 MATLAB ( MATrix LABoratory) is a mathematical computing package that combines numerical analysis, matrix computation, and advanced graphics in a user-friendly environment. MATLAB is a language that is similar C or FORTRAN but has greatly enhanced capabilities. Programs are written and stored in script or function files in ASCII (or text) format called M-files that carry the .m extension (e.g. vtb1_1.m ). MATLAB is available via accounts on gamma, which can be accessed from the X-terminal lab in RUSS 152. To login to use MATLAB, you must first connect to gamma. Do this by clicking on the gamma button and then clicking on the connect button. When prompted, enter your username then password. The first time you log in you should change your password. Do this with the yppasswd command at the prompt. Note: UnIX Is caSe SenSItIve. You next need to set your DISPLAY environment so the main server knows where you are. This will enable your graphics display to be sent to the X-Windows terminal that you are using. Do this by typing setenv DISPLAY machine_number:0.0 where terminal number is something like 184.108.40.206. Be sure to include all numbers and to put a :0.0 on the end (this should be displayed on the front of the terminal). Also, remember the case sensitivity. (If you are running at home without X-terminal capabilities, you can use the command unsetenv DISPLAY and type terminal at the M ATLAB prompt. This does not work well, but you may be able to at least display the graphics.) To use email, I recommend trying pine. To start MATLAB, type matlab from the UNIX prompt. Type demo for a brief introduction to the capabilities of MATLAB. All of the UNIX commands can be used within MATLAB by placing ! in front of them. For example !ls, lists the contents of the current directory. MATLAB is an interactive language. You can use the commandhelp from within MATLAB for help on MATLAB commands. A set of MATLAB commands can be executed by storing them in a script file in your MATLAB path. To execute a script file, type the name of the script file (without the .m ) at the MATLAB prompt. To write these scripts you will need use a UNIX editor. There are several editors to choose from (e.g. vi, axe, dxnotepad, emacs and pico). To start an editor from within M ATLAB type !axe, !vi, !pico... at the M ATLAB command prompt or simply type the editor’s name in lower case from the UNIX prompt. Alternatively, typing filebar at the M ATLAB prompt may simplify this task for you. Of the editors, vi is considered by many to be the hardest to use. I recommend you use dxnotepad, axe, or emacs. Once written, M-files must be saved with the .m extension. If the file is simply a script file (a list of commands that does not take input arguments or return output variables), you can run the program by simply typing the script name without the .m extension (make sure you use the right case. It’s advisable to use all lower case in naming your M-files. All of the student edition of the Vibration Toolbox codes are what you would call function files. They accept an input argument, and some return a result (output argument). This is functionally how commands such as sin , cos, and plot work. Use the command type to view the file vtb1_1 . You can also open it for read-only in an editor if you want to save and modify it to make your own codes. It can be found in the directory /nfs/valhalla/users26/me/jslater/vtoolbox.
( “. and dispar . Alternatively. This allows you to put a help section in your program. the values of P. you won’t be able to mess the file up).dispar) from the M ATLAB prompt where M. K. and U and the inputs are M. and dispar . In this way.dispar) %VTB4_1 Natural frequencies and eigenvectors for an undamped %system. K. K. Also notice that the name of the file appears in the first line.) If you want to obtain the output of a function.Sample script file example. From the MATLAB prompt.” suppresses the output to screen) 3) type b = [7 8 9 10 11 12].U]=vtb4_1(M. Once the function has completed running.*b (notice the “. K.m 14) at the MATLAB prompt type example to run the program A function file is one that takes input arguments and returns output variables to the workspace (or another M-file if it was called from one). and U inside the function will be assigned to the variables P2 .” to signify array or element by element multiplication) 7) type plot(a. you can run the function by typing it as vtb4_1(1. 4) type a (no “. edit the file vtb4_1.3) and the variables M. For instance. 12) To exit the pico editor hit the ctrl and x key at the same time 13) answer yes to save changes to example. the outputs are P. w . and dispar are variables that have already been assigned. you must use output arguments in giving the command (this lets MATLAB know where to store the information). The first line of the function declares that it is a function file.w2.U2] = vtb4_1(M.K. w2 . For instance [P2.dispar) will execute the commands of vtb4_1 using the input variables M.K. You can do this by typing: pico /nfs/valhalla/users26/me/jslater/vtoolbox/vtb4_1. The first few lines appear as: function [P. then plots one versus the other) 1) From MATLAB prompt type !dxnotepad example. if you type help vtb4_1 you will notice the response is the contents of the first set of lines that start with %. all you need to do is type vtb4_1(M. and U2 outside the function in the workspace (or wherever the function was called from).m (defines 2 row vectors. multiplies them. functions can act as stand-alone programs inside MATLAB or as subroutines for other functions or scripts. The rest of the variables internal to the function are local to the function. 10) type title(‘a versus x’).2.m .K. .” this displays contents of a on screen) 5) type b (this displays contents of a on screen) 6) type x = a. and dispar will take on corresponding values inside the function.m 2) type a = [1 2 3 4 5 6]. (Only the output variables of the function will change the values of variables in the workspace.x). w .w.m (Don’t worry. If you want to perform the operation that vtb4_1 has been programmed to do. This should agree with the filename when you create your own function files. 8) type xlabel(‘Array a’). (plots a versus x ). 9) type ylabel(‘Array x’).
cd mydir rmdir mydir man topic lps1 text softlist showquota exit or lo ^c ^z bg jobs %n pwd command & pine Action List files in current directory moves file old to file new copies file old to file new removes filename makes a directory mydir move up 1 directory move into directory mydir removes directory mydir help on topic prints file text to lps1 printer as text shows available software shows user disk space log out escape/kill stop (do not use this to exit MATLAB) continue to run stopped job in background list the names and numbers of all jobs reconnect to stopped job n show present working directory run command in the background Read.Basic UNIX operations. and send email . Command ls mv old new cp old new rm filename mkdir mydir cd . edit..
diary Action help Addition subtraction multiplication division power denotes vector a = [1 2 3] shows variables define matrix A matrix inverse of A transpose of matrix A ([1 3 .5:5 . 3 4] inv(A) A’ plot(x.y) xlabel(‘title’) ylabel(‘title’) title(‘title’) hold figure figure(n) x = 1:5 x = 1:. 2 4]) plots x versus y (they must have same length) assigns name title to x axis of plot assigns name title to y axis of plot assigns name title to the title of plot freezes the plot screen opens a graphics window selects figure number “n” (integer n) generates x = 1 2 3 4 5 in steps of 1 generates x from 1 to 5 in steps of .5 multiplies two arrays element by element divides two arrays element by element used at end of command to suppress output to the screen creates a diary file of what’s on the screen ./ . Command help + * / ^ a = [1 2 3]’ who A=[1 2 .Basic MATLAB commands.* .
This action might not be possible to undo. Are you sure you want to continue?
We've moved you to where you read on your other device.
Get the full title to continue listening from where you left off, or restart the preview.