Title: Introduction%20to%20MATLAB
1Introduction to MATLAB
- Northeastern University College of Computer and
Information Science - Co-op Preparation University (CPU)
10/22/2003
2Overview for 10/22/2003
- Review of topics covered in last session
(10/20/2003) - Review of the MATLAB environment (covered in last
session) - Declaring and manipulating variables
- Useful functions
3Review of 10/20/2003
- Contact Information
- Course Overview
- MATLAB Overview
4Contact Information
- E-mail wmason_at_ccs.neu.edu
- Office Hours Wednesday after class
- Some information available
- http//www.ccs.neu.edu/home/wmason
5Course Overview
6Course Structure
- Week 1 Overview of MATLAB
- History of MATLAB
- Overview of MATLAB environment
- Discussion of MATLAB in co-op
- Week 2 Basic MATLAB
- Simple MATLAB functionality
- Syntax, Commands
- Exercises involving basic MATLAB functionality
7Course Structure, cont 2
- Week 3 Advanced MATLAB Functionality
- Beyond MATLAB as a calculator
- The MATLAB programming language
- Project showcasing MATLABs advanced functionality
8Meeting Times and Locations
- Week 1
- Class 1
- Monday, Oct. 20, 6 - 7 p.m., 257 CN
- Class 2
- Wednesday, Oct. 22, 6 - 7 p.m., 257 CN
- Class 3
- Thursday, Oct. 23, 6 - 7 p.m., 247 CN
9Meeting Times and Locations, cont 2
- Week 2
- Class 1
- Monday, Oct. 27, 6 - 7 p.m., 257 CN
- Class 2
- Wednesday, Oct. 29, 6 - 7 p.m., 257 CN
- Class 3
- Thursday, Oct. 30, 6 - 7 p.m., 247 CN
10Meeting Times and Locations, cont 3
- Week 3
- Class 1
- Monday, Nov. 3, 6 - 7 p.m., 257 CN
- Class 2
- Wednesday, Nov. 5, 6 - 7 p.m., 257 CN
- Class 3
- Thursday, Nov. 6, 6 - 7 p.m., 247 CN
11Coursework
- Collection of exercises
- Will occur during the second week
- Will involve MATLABs basic functionality
- Final project
- Will occur during the final two sessions
- Will cover MATLABs basic and advanced
functionality
12History of MATLAB
- Ancestral software to MATLAB
- Fortran subroutines for solving linear (LINPACK)
and eigenvalue (EISPACK) problems - Developed primarily by Cleve Moler in the 1970s
13History of MATLAB, cont 2
- Later, when teaching courses in mathematics,
Moler wanted his students to be able to use
LINPACK and EISPACK without requiring knowledge
of Fortran - MATLAB developed as an interactive system to
access LINPACK and EISPACK
14History of MATLAB, cont 3
- MATLAB gained popularity primarily through word
of mouth because it was not officially
distributed - In the 1980s, MATLAB was rewritten in C with
more functionality (such as plotting routines)
15History of MATLAB, cont 4
- The Mathworks, Inc. was created in 1984
- The Mathworks is now responsible for development,
sale, and support for MATLAB - The Mathworks is located in Natick, MA
- The Mathworks is an employer that hires co-ops
through our co-op program
16MATLAB GUI
- Launch Pad / Toolbox
- Workspace
- Current Directory
- Command History
- Command Window
17Launch Pad / Toolbox
- Will not be covered
- Launch Pad allows you to start help/demos
- Toolbox is for use with specialized packages
(Signal Processing)
18Workspace
- Allows access to data
- Area of memory managed through the Command Window
- Shows Name, Size (in elements), Number of Bytes
and Type of Variable
19Current Directory
- MATLAB, like Windows or UNIX, has a current
directory - MATLAB functions can be called from any directory
- Your programs (to be discussed later) are only
available if the current directory is the one
that they exist in
20Command History
- Allows access to the commands used during this
session, and possibly previous sessions - Clicking and dragging to the Command window
allows you to re-execute previous commands
21Command Window
- Probably the most important part of the GUI
- Allows you to input the commands that will create
variables, modify variables and even (later)
execute scripts and functions you program
yourself.
22Simple Commands
23who
- who lists the variables currently in the
workspace. - As we learn more about the data structures
available in MATLAB, we will see more uses of
who
24whos
- whos is similar to who, but also gives size and
storage information - s whos(...) returns a structure with these
fields name variable name size variable size
bytes number of bytes allocated for the array
class class of variable and assigns it to the
variable s. (We will discuss structures more).
25Save
- save saves workspace variables on disk
- save filename stores all workspace variables in
the current directory in filename.mat - save filename var1 var2 ... saves only the
specified workspace variables in filename.mat.
Use the wildcard to save only those variables
that match the specified pattern.
26Clear
- clear removes items from workspace, freeing up
system memory - Examples of syntax
- clear
- clear name
- clear name1 name2 name3 ...
27clc
- Not quite clear
- clc clears only the command window, and has no
effect on variables in the workspace.
28Load
- load - loads workspace variables from disk
- Examples of Syntax
- load
- load filename
- load filename X Y Z
29Declaring a variable in MATLAB
- Not necessary to specify a type. (Such as int or
float) - Several kinds of variables
- Vector
- Matrix
- Structure
- Cell array
30Declaring a variable, cont 2
- For an integer or floating point number simply
set a variable name equal to some character - Ex. A 5
- Or A 5
31Sidenote 1
- The presence or lack of a semi-colon after a
MATLAB command does not generate an error of any
kind - The presence of a semi-colon tells MATLAB to
suppress the screen output of the command
32Sidenote 1, cont 2
- The lack of a semi-colon will make MATLAB output
the result of the command you entered - One of these options is not necessarily better
than the other
33Declaring a variable, cont 3
- You may now use the simple integer or float that
you used like a normal number (though internally
it is treated like a 1 by 1 matrix) - Possible operations
- , -, /
- Many functions (round(), ceil(), floor())
34Declaring a variable, cont 4
- You may also make a vector rather simply
- The syntax is to set a variable name equal to
some numbers, which are surrounded by brackets
and separated by either spaces or commas - Ex. A 1 2 3 4 5
- Or A 1,2,3,4,5
35Declaring a variable, cont 5
- You may also declare a variable in a general
fashion much more quickly - Ex. A 1110
- The first 1 would indicate the number to begin
counting at - The second 1 would be the increase each time
- And the count would end at 10
36Declaring a variable, cont 6
- Matrices are the primary variable type for MATLAB
- Matrices are declared similar to the declaration
of a vector - Begin with a variable name, and set it equal to a
set of numbers, surrounded by brackets. Each
number should be seperated by a comma or
semi-colon
37Declaring a variable, cont 7
- The semi-colons in a matrix declaration indicate
where the row would end - Ex. A 1,23,4 would create a matrix that
looks like - 1 2
- 3 4
38Declaring a variable, cont 7
- Matrices may be used as normal variables now.
Multiplying is already defined for matrices, and
additional code does not need to be written.
39Declaring a variable, cont 8
- The final type of variable we will discuss today
will be a struct. - The command struct is used to create a structure
- Syntax
- s struct('field1',,'field2',,...)
- s struct('field1',values1,'field2',values2,...)
40Declaring a variable, cont 9
- A simple declaration of a structure is as
follows - Student.name Joe
- Student.age 23
- Student.major Computer Science
41Declaring a variable, cont 10
- Arrays of structures are possible.
- Taking the previous example, if one were to
write - Student(2).name Bill
- etc
- Then the array would be created for you.
42Declaring a variable, cont 11
- Structures can group information, but methods are
not written for them.
43End
Another satisfied MATLAB user!