Creating and Concatenating Matrices . . . . . . . . . . . . . . . 1-2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Constructing a Simple Matrix . . . . . . . . . . . . . . . . . . . . . . . 1-3
Specialized Matrix Functions . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Concatenating Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7
Matrix Concatenation Functions . . . . . . . . . . . . . . . . . . . . . 1-8
Generating a Numeric Sequence . . . . . . . . . . . . . . . . . . . . . 1-10
Matrix Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
Accessing Single Elements . . . . . . . . . . . . . . . . . . . . . . . . . . 1-12
Linear Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Functions That Control Indexing Style . . . . . . . . . . . . . . . . 1-13
Accessing Multiple Elements . . . . . . . . . . . . . . . . . . . . . . . . 1-14
Using Logicals in Array Indexing . . . . . . . . . . . . . . . . . . . . 1-16
Single-Colon Indexing with Different Array Types . . . . . . . 1-20
Indexing on Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-20
Getting Information About a Matrix . . . . . . . . . . . . . . . . . 1-22
Dimensions of the Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22
Classes Used in the Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23
Data Structures Used in the Matrix . . . . . . . . . . . . . . . . . . 1-24
Resizing and Reshaping Matrices . . . . . . . . . . . . . . . . . . . 1-25
Expanding the Size of a Matrix . . . . . . . . . . . . . . . . . . . . . . 1-25
Diminishing the Size of a Matrix . . . . . . . . . . . . . . . . . . . . . 1-29
Reshaping a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-30
Preallocating Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-32
Shifting and Sorting Matrices . . . . . . . . . . . . . . . . . . . . . . 1-35
Shift and Sort Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-35
Shifting the Location of Matrix Elements . . . . . . . . . . . . . . 1-35
Sorting the Data in Each Column . . . . . . . . . . . . . . . . . . . . 1-37
Sorting the Data in Each Row . . . . . . . . . . . . . . . . . . . . . . . 1-37
Sorting Row Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-38