CS100J, Fall 2001 Tues 11/26 Lecture 24 ------------------------------------------------------------------------------- Announcements: + T3 grading is tonight and tomorrow + P6 and makeup, which are combined, due Tues 12/4 + E11 due Thurs 11/28: redo Prelim 1's Problem 3 in MATLAB ------------------------------------------------------------------------------- Topics: + no more Java, except for $args$ on last lecture + MATLAB - development environment - files and path - language - flow control ------------------------------------------------------------------------------- What is MATLAB? + stands for MATtrix LABoratory + From MATLAB's Help document, Getting Started: Introduction: "MATLABŪ is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation." ------------------------------------------------------------------------------- Running MATLAB: + OS: - Windows: Programs menu - UNIX: enter $matlab$ at the command prompt - Mac: nope (unless you have older version) + First thing to do: - select Help->MATLAB Help menu - MATLAB opens the Help Browser - select MATLAB:Getting Started and read everything ------------------------------------------------------------------------------- Development environment: + see in Help Browser: - Getting Started: Development Environment: MATLAB Desktop - MATLAB:Using MATLAB:Development Environment + two "places" to program: - Command Window (workspace) - Edit Window (M-File) ------------------------------------------------------------------------------ Command Window + MATLAB's "main" window - enter commands at prompt (>>) - type a command and then press Return or Enter - this is the "brain" + carves up memory for programs + acts upon commands and lines of code + The "brain" is called the MATLAB workspace or base workspace: - processes and evaluates commands - remembers variables and commands you have entered + key strokes for short cuts (see Development Environment: Using the Desktop: Keyboard Shortcuts and Accelerators): + Handy commands: more on % turn on pager (spacebar) clc % clear screen clear % clear variable assignments format % set output preferences (see also File-> Preferences menu) ver % version of MATLAB ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- Edit Window and M-Files + using the command window for all programs can be tedious + store statements in separate file called M-File + create file, store statements, run "program" in Command Window - create ASCII files: File->New->M-File or use your own text editor - name of file is the program name example) blah.m has the name $blah$ + 2 kinds of files: - scripts: collections of commands that you could enter at the prompt - functions: a script that is labeled with a name that can take arguments and return values ------------------------------------------------------------------------------- Path and working directory: + see Development Environment: Workspace, Path, and File Operations + PATH: the directories/folders where M-Files are stored - MATLAB needs to find your file to run it - MATLAB will search from beginning to end when you use a file - MATLAB stores the path in a special variable (pathdef) - enter PATH to see current path + set path by File->Set Path... - add a directory (also called folder) - position is important! + current working directory: - MATLAB keeps track of the most curret directory to find files - called the CURRENT WORKING DIRECTORY (from UNIX) - PWD shows the cwd (see top bar on desktop) + names (see Development Environment: Workspace, Path, and File Operations: Search Path): - MATLAB checks if a name is a variable - then MATLAB checks if a name is a builtin function - MATLAB checks the CWD - MATLAB searches the path, from top to bottom ------------------------------------------------------------------------------- Handy file commands: edit : open a new M-File path : show current path editpath : modify path addpath : add a directory to the path pwd : show the current working directory cd : change the current working directory what : list M-Files in current directory type : show contents of M-File in Command Window exist : check if M-file exists ls : list all files in current working directory ------------------------------------------------------------------------------- Language Elements + Characters - usually keyboard characters (ASCII text) - see characters.txt + Tokens, Expressions, Statements: - see tokens.txt and statements.txt ------------------------------------------------------------------------------- Statements: + Input/Output: see io.txt and readIntPrompt.txt + Selection: see matlabifhelp.txt + Repetition: see matlabwhilehelp.txt matlabforhelp.txt + Generating values: see values.txt -------------------------------------------------------------------------------