1

 Goals
 Understand how MATLAB uses arrays
 and matrices
 Prepare simple graphs

2

 Math overview: arrays, vectors, & matrices
 Creating array variables in MATLAB
 Calculations with array variables
 Elementbyelement operators
 Creating simple graphs in MATLAB

3

 An array can be regarded as a collection of variables of the same type.
 The advantage of using array:

4

 A matrix is a rectangular array of mathematical elements
 singleelement array (scalar)
 1D matrices are called vectors  can be arranged as a single row of
elements or as a
single column

5

 2D matrices have 2 or more rows and 2 or more columns.

6


7


8

 What’s the value for
 A(2)?
 B(1,1), B(3, 2)?
 How about B(5, 4)?
 Can you imagine what a 3D array looks like? How about 4D?

9


10

 Using the colon (:) operator:
 In general the colon (:) operator is

11


12


13


14


15


16


17


18


19


20


21


22


23

 Will be discussed in detail later on.
 Script MFile is a collection of MATLAB commands saved as a file with .m
extension name.
 This saves time for repetitive typing.
 Try the previous example using script Mfile.

24

 Matlab text Chapter 4,
 Section 1 (XY plotting functions)
 Section 2 (Subplots and overlay plots)
 pgs 127143.

25

 We use a two dimensional array to keep the grades of a class. This class
has ten students.
 There are altogether 6 homework, 1 midterm and one final, two lab
reports.
 Each student’s information is as follows:

26


27

 Please use a 10 by 11 array to store the student ID numbers, and all the
grades. Hint: use script mfile to save repetitive typing.
 Use input( ) and display( ) functions to display the grade of any
homework of a student.

28

 Several mistakes were made when entering then grades. Here are the
corrections:
 For John C., The grade for third homework is 9.5
 Midterm for George B is 85.
 Please make corrections without reentering the whole array.
