CS99 Fall 2002 Lab 1 (9/3) 0. Objectives: + Review administrative procedures - How lab is run - Sign up for NetPrint - Tour of course homepage + Introduction to Matlab - Command Window - MATLAB commands (addition) - Editing and running a script - Saving and printing a file + Homework hints What to hand in: + e-mail to TA the file described in 3.0 1. Administrative Procedures 1.1 Lab requirements + you must attend every lab (sign attendance sheet) + you *attempt* to complete the exercise and submit it + you must participate + you may work alone or in groups of any size 1.2 Net-Print Do you have an account? If not, see http://www.cit.cornell.edu/net-print/ 1.3 Course Homepage + Go to http://www.cs.cornell.edu/courses/cs99. + Navigating the site 2.0 Introduction to MATLAB 6.1 + See http://www.mathworks.com for the MATLAB company's website. + Select Classfiles and Programs to run MATLAB. + Play time! 2.1 Commands in the Command Window + You may enter commands here that the MATLAB "brain" will process. + You enter commands after the PROMPT, which looks like >> + If we say, enter $blah$, you type the letters b, l, a, and h with no spaces in between them after the prompt and then press the Enter key. + Use the arrow keys, Del, and Backspace to edit the command if you make a mistake. 2.2 General Help + For general help, enter $help$. + To find help on something called $blah$, you would enter $help blah$. 2.3 Demonstrating the Command Window + enter $1+1$: Sample session: >> 1+1 ans = 2 + MATLAB computes the expression 1+1 and reports the answer 2. + Yes, this really does resemble a calculator! 3.0 Demonstrating a Simple Script You will write your first program! You can write commands in a separate file that MATLAB will understand and "compute". A Script File is a user-created file with a sequence of MATLAB commands in it. The file must be saved with a '.m' extension to its name. A script file is executed by typing its name (without the '.m' extension) at the command prompt. MATLAB scripts are essentially programs because they contain a sequence of instructions that MATLAB executes. + From the menu, select File-->New-->M-file. + Inside the window, enter the following: % My first program! disp('Hello, world!') 1+1 + Select File-->Save As... . + In the window that pops up, choose the file name $hello.m$. + In the main window, make sure that current directory is the same directory as where you saved your program. This process is known as SETTING YOUR PATH. A path is a location of a file or a directory/folder that contains files. You may type the directory/folder or select File-->Set Path. + After your path is set, enter $hello$ at the prompt in the command window. + MATLAB will generate output from your program if you made no mistake! 4.0 Some General Commands For the Command Window diary filename saves the diary of a session clc clears the command screen ^C aborts any job inside MATLAB exit exits MATLAB 5.0 Tutorials/Demos More practice (just showing off some commands: don't worry about not knowing them!): >> theta=linspace(0, 2*pi, 100); >> x=cos(theta); >> y=sin(theta); >> plot(x,y); >> title('circle of unit radius'); + To run a tutorial, enter $demo$ at prompt.