# Matlab Study

Topics: Matrix, Dot product, Row vector Pages: 17 (3452 words) Published: February 4, 2013
Introduction to Programming in MATLAB

6.094

Lecture 1: Variables, Scripts, and Operations

Danilo Šćepanović
IAP 2010

Course Layout
• Lectures
1: 2: 3: 4: 5:

Variables, Scripts and Operations Visualization and Programming Solving Equations, Fitting Images, Animations, Advanced Methods Optional: Symbolic Math, Simulink

Course Layout
• Problem Sets / Office Hours
One per day, should take about 3 hours to do Submit doc or pdf (include code, figures) No set office hours but available by email

• Requirements for passing
Attend all lectures Complete all problem sets (-, √, +)

• Prerequisites
Basic familiarity with programming Basic linear algebra, differential equations, and probability

Outline
(1) (2) (3) (4) (5) Getting Started Scripts Making Variables Manipulating Variables Basic Plotting

Getting Started
• To get MATLAB Student Version for yourself » https://msca.mit.edu/cgi-bin/matlab Use VPN client to enable off-campus access Note: MIT certificates are required

• Open up MATLAB for Windows

• On Athena » add matlab » matlab &

Current directory

Workspace

Command Window

Command History

Courtesy of The MathWorks, Inc. Used with permission.

Making Folders
• Use folders to keep your programs organized
• To make a new folder, click the ‘Browse’ button next to ‘Current Directory’

• Click the ‘Make New Folder’ button, and change the name of the folder. Do NOT use spaces in folder names. In the MATLAB folder, make two new folders: IAPMATLAB\day1 • Highlight the folder you just made and click ‘OK’ • The current directory is now the folder you just created • To see programs outside the current directory, they should be in the Path. Use File-> Set Path to add folders to the path

Customization
• File Preferences
Allows you personalize your MATLAB experience

Courtesy of The MathWorks, Inc. Used with permission.

MATLAB Basics
• MATLAB can be thought of as a super-powerful graphing calculator Remember the TI-83 from calculus? With many more buttons (built-in functions)

• In addition it is a programming language
MATLAB is an interpreted language, like Java Commands executed line by line

Help/Docs
• help The most important function for learning MATLAB on your own • To get info on how to use a function: » help sin Help lists related functions at the bottom and links to the doc • To get a nicer version of help with examples and easy-toread descriptions: » doc sin • To search for a function by specifying keywords: » doc + Search tab

Outline
(1) (2) (3) (4) (5) Getting Started Scripts Making Variables Manipulating Variables Basic Plotting

Scripts: Overview
• Scripts are
collection of commands executed in sequence written in the MATLAB editor saved as MATLAB files (.m extension)

• To create an MATLAB file from command-line » edit helloWorld.m • or click

Courtesy of The MathWorks, Inc. Used with permission.

Scripts: the Editor
* Means that it's not saved Line numbers MATLAB file path Debugging tools Real-time error check

Help file

Possible breakpoints

Courtesy of The MathWorks, Inc. Used with permission.

Scripts: Some Notes
• COMMENT!
Anything following a % is seen as a comment The first contiguous comment becomes the script's help file Comment thoroughly to avoid wasting time later

• Note that scripts are somewhat static, since there is no input and no explicit output • All variables created and modified in a script exist in the workspace even after it has stopped running

Exercise: Scripts
Make a helloWorld script • When run, the script should display the following text: Hello World! I am going to learn MATLAB!

• Hint: use disp to display strings. Strings are written between single quotes, like 'This is a string'

Exercise: Scripts
Make a helloWorld script • When run, the script should display the following text: Hello World! I am going to learn MATLAB!

• Hint: use...