MATLAB Programming
MATLAB Programming MATLAB Programming
1 Data Structures Multidimensional Arrays An array having more than two dimensions is called a multidimensional array in MATLAB. Most of the operations that you can perform on matrices (i.e., two-dimensional arrays) can also be done on multidimensional arrays. This section shows how to create and manipulate these arrays. It covers • “Overview” on page 1-52 • “Creating Multidimensional Arrays” on page 1-54 • “Accessing Multidimensional Array Properties” on page 1-57 • “Indexing Multidimensional Arrays” on page 1-58 • “Reshaping Multidimensional Arrays” on page 1-62 • “Permuting Array Dimensions” on page 1-64 • “Computing with Multidimensional Arrays” on page 1-66 • “Organizing Data in Multidimensional Arrays” on page 1-67 • “Multidimensional Cell Arrays” on page 1-69 • “Multidimensional Structure Arrays” on page 1-70 Overview Multidimensional arrays in MATLAB are an extension of the normal two-dimensional matrix. Matrices have two dimensions: the row dimension and the column dimension. You can access a two-dimensional matrix element with two subscripts: the first representing the row index, and the second representing the column index. 1-52
Multidimensional Arrays Multidimensional arrays use additional subscripts for indexing. A three-dimensional array, for example, uses three subscripts: • The first references array dimension 1, the row. • The second references dimension 2, the column. • The third references dimension 3. This illustration uses the concept of a page to represent dimensions 3 and higher. To access the element in the second row, third column of page 2, for example, you use the subscripts (2,3,2). 1-53
- Page 26 and 27: 1 Data Structures Empty Matrices, S
- Page 28 and 29: 1 Data Structures (shown as E below
- Page 30 and 31: 1 Data Structures 0 0 0 0 0 0 0 0 0
- Page 32 and 33: 1 Data Structures 0.6068 0.7621 0.8
- Page 34 and 35: 1 Data Structures 3 5 7 3 5 7 3 5 7
- Page 36 and 37: 1 Data Structures A = 3:0.2:3.8 A =
- Page 38 and 39: 1 Data Structures 5000 50 B = [int8
- Page 40 and 41: 1 Data Structures class(x) ans = si
- Page 42 and 43: 1 Data Structures Matrix Indexing T
- Page 44 and 45: 1 Data Structures A used in the pre
- Page 46 and 47: 1 Data Structures 16 5 9 4 . . . 12
- Page 48 and 49: 1 Data Structures Getting Informati
- Page 50 and 51: 1 Data Structures Function islogica
- Page 52 and 53: 1 Data Structures This example runs
- Page 54 and 55: 1 Data Structures A = 10 20 30 40 5
- Page 56 and 57: 1 Data Structures This changes matr
- Page 58 and 59: 1 Data Structures A = [1+9i 2-8i 3+
- Page 60 and 61: 1 Data Structures rp = rp + blocksi
- Page 62 and 63: 1 Data Structures A = [1:8; 11:18;
- Page 64 and 65: 1 Data Structures rand('state', 0);
- Page 66 and 67: 1 Data Structures OperatingonDiagon
- Page 68 and 69: 1 Data Structures Empty Matrices, S
- Page 70 and 71: 1 Data Structures These operations
- Page 72 and 73: 1 Data Structures Use the isscalar
- Page 74 and 75: 1 Data Structures Full and Sparse M
- Page 78 and 79: 1 Data Structures As you add dimens
- Page 80 and 81: 1 Data Structures Generating Arrays
- Page 82 and 83: 1 Data Structures • size — Retu
- Page 84 and 85: 1 Data Structures For example, cons
- Page 86 and 87: 1 Data Structures Avoiding Ambiguit
- Page 88 and 89: 1 Data Structures Permuting Array D
- Page 90 and 91: 1 Data Structures Computing with Mu
- Page 92 and 93: 1 Data Structures • As multivaria
- Page 94 and 95: 1 Data Structures A{2,2} = 7; B{1,1
- Page 96 and 97: 1 Data Structures Summary of Matrix
- Page 98 and 99: 1 Data Structures Functions to Dete
- Page 100 and 101: 1 Data Structures 1-76
- Page 102 and 103: 2 Data Types Cell Arrays (p. 2-94)
- Page 104 and 105: 2 Data Types Data Type Summary The
- Page 106 and 107: 2 Data Types Numeric Types Numeric
- Page 108 and 109: 2 Data Types the two equally nearby
- Page 110 and 111: 2 Data Types x = x = 127 -128 Also,
- Page 112 and 113: 2 Data Types Set the warning state
- Page 114 and 115: 2 Data Types Floating-Point Numbers
- Page 116 and 117: 2 Data Types isfloat(x) ans = 1 You
- Page 118 and 119: 2 Data Types In this example, 7.5 d
- Page 120 and 121: 2 Data Types 8.881784197001252e-016
- Page 122 and 123: 2 Data Types Note that the order of
- Page 124 and 125: 2 Data Types Complex Numbers Comple
Multidimensional Arrays<br />
Multidimensional arrays use additional subscripts for indexing. A<br />
three-dimensional array, for example, uses three subscripts:<br />
• The first references array dimension 1, the row.<br />
• The second references dimension 2, the column.<br />
• The third references dimension 3. This illustration uses the concept of a<br />
page to represent dimensions 3 and higher.<br />
To access the element in the second row, third column of page 2, for example,<br />
you use the subscripts (2,3,2).<br />
1-53