210 likes | 334 Views
Scientific Programming Using MATLAB, Fall 2011-2012. TIRGUL #1: Introduction TA: Noa Liscovitch. Course logistics – general info. Tirgul hours: Tuesday, 10am Location: Computers room #213 Tirgul includes: Lecture reinforcement (a little) Practice (mostly) Contact information:
E N D
Scientific Programming Using MATLAB, Fall 2011-2012 TIRGUL #1: Introduction TA: NoaLiscovitch
Course logistics – general info • Tirgul hours: Tuesday, 10am • Location: Computers room #213 • Tirgul includes: • Lecture reinforcement (a little) • Practice (mostly) • Contact information: • Room #109, 03-5317292 • biumatlab@gmail.com • If you have a laptop - bring it to class.
Course logistics – assignments & grades • 6 homework assignments, 2 weeks for each. Submission deadline - Mondays, 24:00 • 10% each • Final project/quiz • 40% • Submission instructions are available at the course website. • neurint.ls.biu.ac.il
Programming skills in Neuroscience • Math and computation • Algorithm development • Modeling • Simulations • Data analysis • Data visualization • Self Sufficiency
What is MATLAB? • MATLAB = MATrix LABoratory • A high-level programming language for technical computing • A corresponding work-environment
Why use MATLAB? • One program encapsulates entire work process: • Importing data from any format • Countless analysis tools and functions • Result representation • Can design new analysis tools • Simple and user friendly programming language
MATLAB Workspace • Open MATLAB • The workspace includes: • Command Window • Script editor / debugger • Variable editor • Workspace • Current directory • Command History • Menus • Toolbars
Workspace / Current directory Script editor / Debugger Command history Command window
The MATLAB command window • Where commands are executed • >> type them here, then <enter> • Multiple commands need to be separated by ; • Where results are displayed • To suppress display, end command with ; • Some shortcuts: • - recall previous line • - recall next line • Esc - clear line • Home - move to beginning of line • End - move to end of line
Current Directory (CD) • Where MATLAB: • Looks for your functions and variables • Saves new m-files and variables • Need to specify CD at the beginning of work • To get your CD, simply type cd/pwd • To change CD: cd(‘new directory’) • Example: cd(‘C:\Documents\Noa\My Documents\MATLAB\’) • Move up a directory: cd ..
Some more useful commands dir / ls – list of all files and directories in the current directory mkdir – make a new directory rmdir – remove a directory clc – clear command window
Error messages • MATLAB commands need to be written perfectly and are case-sensitive. • cd • C:\Documents and Settings\Noa\Desktop • CD • ??? Undefined function or variable 'CD'.
MATLAB search path • Used by MATLAB to locate files • By default, the files supplied with MATLAB are included in the path • When creating new MATLAB related files – add containing folders to search path • path - View MATLAB's directory search path • addpath - Add directories to MATLAB's search path • addpath(genpath(dirName)) – recursively add directory with all subdirectories.
Other workspace components • Command history • Stores recent commands • To execute a code-line, Double click it • Workspace • Displays current variables, types and values • Variable editor • View and edit variables
A MATLAB Program • 2 types: • Scripts • Functions (to be discussed later in the semester) • Saved as .m files • Text files that MATLAB can run • Running a program: • Type name in the command window • “Run” from editor toolbar • The file needs to be in your current directory!
Scripts • Store sequences of commands • ‘Running a script’ = executing the commands in it • To run a part of it: mark lines + F9 • Script example: pwd mkdir(‘newDir’) ls cd(‘newDir’) cd .. rmdir(‘newDir’) dir
Scripts - pointers • Lines are numbered • Find & Replace • Comments • % - all code in the same line after it is commented. • Comment/uncomment = Ctrl+R/Ctrl+T
Creating and Opening Scripts • Creating a new script: • Menu: File New • Toolbar: ‘‘New M file’’ icon • Opening an existing script: • Menu: File Open • Toolbar: ‘‘Open file’’ icon • Command line: open(‘filename’) • The script is then displayed in the editor.
Help • help command_name – details of the command syntax, usage and options • Example: help clc • Helpdesk (F1) - opens interactive help: • Contents • Index • Best for general information about a subject • Search • Best for specific function names • Demos
Online help • MathWorks web site: • http://www.mathworks.com/ • Google: type ‘MATLAB’ and keywords • Countless MATLAB tutorials on the web
Practice • Open MATLAB • Create a new script that: • Creates your own course directory on the desktop • Changes current directory to your course directory • Shows current directory path • Adds your current directory to MATLAB path • Add a comment, with a short explanation about your script • Save the script • Run the script from the command window