## Table of Contents

1. Introduction to MATLAB

1.1 Solving engineering problems with MATLAB

1.2 MATLAB background

1.3 MATLAB and the interpreter

1.4 Computer basics

1.5 Binary numbers

1.6 A brief tour of a computer

2. Variables

2.1 Variables and assignments

2.2 Identifiers

2.3 Numeric variables

2.4 Numeric expressions

2.5 Accuracy and rounding error

2.6 Mathematical constants

2.7 Repeated commands and the up-arrow key

2.8 String scalars

2.9 Logical variables

2.10 Equality and relational operators

2.11 Logical operators

2.12 Logic short circuit evaluation

2.13 Logic precedence rules

3. Scripts/Fcts

3.1 Scripts

3.2 Comments and clear code

3.3 Custom functions: Basics

3.4 Internal mathematical functions

3.5 Basic input

3.6 Basic output I: disp

3.7 Basic output II: fprintf

3.8 Floating-point formatting in fprintf

4. 1D Array Basics

4.1 Introduction to arrays

4.2 Row arrays

4.3 Constructing row arrays

4.4 Multi-element row array indexing using integer arrays

4.5 Multi-element row array indexing using logical arrays

4.6 Row array resizing

4.7 More indexing

4.8 Functions to create numeric row arrays

4.9 Relational operators and row arrays

4.10 Comparing floating-point numbers for equality

4.11 Column arrays

4.12 Further study: MATLAB programming environment

5. 1D Array Advanced

5.1 1D element-wise arithmetic operators

5.2 Logical operators and 1D arrays

5.3 Relational operators and 1D arrays

5.4 Logical indexing

5.5 Functions and 1D arrays

5.6 Saving and loading variables

6. 1D Array Apps

6.1 Incremental programming: Green Monster example

6.2 Audio signal processing

6.3 Rounding functions

6.4 Remainder and modulus functions

6.5 Summation function

6.6 Complex number functions

6.7 Statistics functions

6.8 Pseudo-random number generators

6.9 Discrete integer mathematics functions

6.10 Rational approximation function

7. 2D Array Basics

7.1 2D arrays: Introduction

7.2 Indexing an element in a 2D array

7.3 Concatenation

7.4 Multi-element 2D array indexing using integer arrays

7.5 Indexing rows and columns using a single colon

7.6 Manipulating 2D arrays using a single colon

7.7 Multi-element 2D array indexing using logical arrays

7.8 Defining logical indexing arrays using relational expressions

7.9 Indexing 2D arrays using the end keyword

7.10 Additional 2D array material

8. 2D Array Advanced

8.1 Dimensional properties of arrays

8.2 Elementary 2D arrays

8.3 Array manipulation

8.4 Replicating and tiling arrays

8.5 Reshaping arrays

8.6 Find function

8.7 Sorting

8.8 2D element-wise arithmetic operators

8.9 Logical functions for arrays

8.10 Functions and two-dimensional arrays

9. Data Visualization

9.1 Simple plotting

9.2 2D data plots I

9.3 3D and higher arrays

9.4 True color/RGB image

9.5 Indexed color image

9.6 Grayscale/intensity images

9.7 Common image file operations

9.8 2D data plots II

9.9 3D line plots

9.10 Rectangular data grids

9.11 Triangular data grids

9.12 Surface and mesh plots

9.13 Scatter plots

9.14 Animating plots with loops

9.15 Additional plotting material

10. Branches

10.1 If-else statement

10.2 Relational operators

10.3 Multiple branches

10.4 Logical operators

10.5 Switch statement

11. Loops

11.1 While loops

11.2 More while examples

11.3 Counting

11.4 For loops

11.5 Nested loops

11.6 Loops and arrays

11.7 Break and continue

12. Custom Functions

12.1 Scripts with local functions

12.2 Functions with local functions

12.3 Nested functions

12.4 Anonymous functions

12.5 Function handles

12.6 Scope of variables

12.7 Global variables

12.8 Persistent variables

12.9 Recursion

12.10 Counting function arguments

13. Strings and Characters

13.1 Strings

13.2 Character vector

13.3 Strings append and combine

13.4 String conversions

13.5 Character vector conversions

13.6 Text comparisons

13.7 Text qualities

13.8 Find text

13.9 Manipulating text

14. Structures

14.1 Grouping data: Structure

14.2 Defining a structure

14.3 Accessing a structure

14.4 MATLAB functions for structures

14.5 Structures as function arguments

14.6 Structure with array fields

14.7 Array of structures

14.8 Structure example: Seat reservation system

15. MATLAB Data Structures

15.1 Data classes

15.2 Cell Arrays: Construction

15.3 Cell Arrays: Accessing

15.4 Cell array example

15.5 Categorical arrays

15.6 Table

16. Object Oriented Programming

16.1 Objects: Introduction

16.2 Classes: Introduction

16.3 Class properties

16.4 Class methods

16.5 Class example: Seat reservation system

16.6 Operator overloading

16.7 Mutators, accessors, and private helpers

16.8 Handle classes

16.9 Handle class example: Ball drop

17. GUIs

17.1 Handle graphics objects

17.2 Message dialog boxes

17.3 Input dialog boxes

17.4 Sequential GUI programming

17.5 Event-driven GUI programming: App designer

17.6 Further Study

18. Applied Mathematics

18.1 Interpolation

18.2 Curve fitting: Least Squares Regression

18.3 Numerical integration

18.4 Numerical differentiation

18.5 Nonlinear equations: Zeros

19. Linear Algebra I

19.1 Vectors

19.2 Matrices

19.3 Matrix transpose

19.4 Matrix calculations

19.5 Square matrices

19.6 Elementary square matrices

19.7 Linear systems

19.8 Square matrices: Solving Ax = b

19.9 Triangular matrix linear equation solvers

19.10 Gaussian elimination I

19.11 Gaussian elimination II

19.12 Gauss-Jordan elimination

20. Linear Algebra II

20.1 Matrix rank

20.2 Properties of the row-echelon matrices of A

20.3 Vector spaces I

20.4 Vector spaces II

20.5 Row vector space of A

20.6 Column vector space of A

20.7 Null vector space of A

20.8 Null vector space of transpose A

20.9 Solutions to Ax = b

20.10 Least squares solutions to Ax=b

20.11 Eigenvalues and eigenvectors

21. Appendix: Symbolic Math

21.1 Symbolic variables

21.2 Symbolic expressions

21.3 Formula manipulation and simplification

21.4 Operators

21.5 Plots

21.6 Series

21.7 Limits

21.8 Algebraic equations

21.9 Calculus

21.10 Ordinary differential equations

21.11 Converting between symbolic and numeric objects

21.12 Linear algebra II

21.13 Vector calculus

21.14 Integral transforms

21.15 Mathematical functions

21.16 Special functions

## What You’ll Find In This zyBook:

### More action with less text.

- Strong emphasis on array operations
- ~850 participation activities: Questions, animations, tools
- Fully embedded MATLAB® homework system
- Ideal for self-paced independent learning, as well as for a traditional class

zyBooks is the first partner to offer MATLAB in the cloud and integrated within a textbook. MATLAB® and the L-shaped membrane logo® are registered trademarks of The MathWorks, Inc.

## The zyBooks Approach

### Less text doesn’t mean less learning.

Provides interactive learning of programming foundations and MATLAB®. The material emphasizes a solid understanding of 1D and 2D arrays, teaching effective use of the array/matrix operations that make MATLAB such a powerful engineering tool. Numerous applications demonstrate the usefulness of arrays in practice. The material covers key programming constructs (scripts, functions, branches, loops, etc.), cell arrays, GUIs, and much more. Includes numerous accompanying MATLAB problems with real-time feedback through the integrated homework system.

## Authors

**Andre Knoesen**

*Professor of Electrical and Computer Engineering University of California, Davis*

**Rajeevan Amirtharajah**

*Professor of Electrical and Computer Engineering University of California, Davis*