1 / 21

Scientific Programming Using MATLAB, Fall 2011-2012

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:

Download Presentation

Scientific Programming Using MATLAB, Fall 2011-2012

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Scientific Programming Using MATLAB, Fall 2011-2012 TIRGUL #1: Introduction TA: NoaLiscovitch

  2. 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.

  3. 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

  4. Programming skills in Neuroscience • Math and computation • Algorithm development • Modeling • Simulations • Data analysis • Data visualization • Self Sufficiency

  5. What is MATLAB? • MATLAB = MATrix LABoratory • A high-level programming language for technical computing • A corresponding work-environment

  6. 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

  7. MATLAB Workspace • Open MATLAB • The workspace includes: • Command Window • Script editor / debugger • Variable editor • Workspace • Current directory • Command History • Menus • Toolbars

  8. Workspace / Current directory Script editor / Debugger Command history Command window

  9. 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

  10. 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 ..

  11. 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

  12. 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'.

  13. 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.

  14. 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

  15. 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!

  16. 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

  17. Scripts - pointers • Lines are numbered • Find & Replace • Comments • % - all code in the same line after it is commented. • Comment/uncomment = Ctrl+R/Ctrl+T

  18. 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.

  19. 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

  20. Online help • MathWorks web site: • http://www.mathworks.com/ • Google: type ‘MATLAB’ and keywords • Countless MATLAB tutorials on the web

  21. 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

More Related