MATLAB Programming
MATLAB Programming MATLAB Programming
1 Data Structures Summary of Matrix and Array Functions This section summarizes the principal functions used in creating and handling matrices. Most of these functions work on multidimensional arrays as well. FunctionstoCreateaMatrix Function [a,b] or [a;b] accumarray blkdiag cat diag horzcat magic ones rand repmat vertcat zeros Description Create a matrix from specified elements, or concatenate matrices together. Construct a matrix using accumulation. Construct a block diagonal matrix. Concatenate matrices along the specified dimension. Create a diagonal matrix from a vector. Concatenate matrices horizontally. Create a square matrix with rows, columns, and diagonals that add up to the same number. Create a matrix of all ones. Create a matrix of uniformly distributed random numbers. Create a new matrix by replicating or tiling another. Concatenate two or more matrices vertically. Create a matrix of all zeros. Functions to Modify the Shape of a Matrix Function ctranspose flipdim fliplr Description Flip a matrix about the main diagonal and replace each element with its complex conjugate. Flip a matrix along the specified dimension. Flip a matrix about a vertical axis. 1-72
Summary of Matrix and Array Functions Functions to Modify the Shape of a Matrix (Continued) Function flipud reshape rot90 transpose Description Flipamatrixaboutahorizontalaxis. Change the dimensions of a matrix. Rotate a matrix by 90 degrees. Flip a matrix about the main diagonal. Functions to Find the Structure or Shape of a Matrix Function isempty isscalar issparse isvector length ndims numel size Description Return true for 0-by-0 or 0-by-n matrices. Return true for 1-by-1 matrices. Return true for sparse matrices. Return true for 1-by-n matrices. Return the length of a vector. Return the number of dimensions in a matrix. Return the number of elements in a matrix. Return the size of each dimension. Functions to Determine Data Type Function iscell ischar isfloat isinteger islogical isnumeric Description Return true if the matrix is a cell array. Return true if matrix elements are characters or strings. Determine if input is a floating point array. Determine if input is an integer array. Return true if matrix elements are logicals. Return true if matrix elements are numeric. 1-73
- 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 76 and 77: 1 Data Structures Multidimensional
- 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 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
- Page 126 and 127: 2 Data Types NaN MATLAB represents
- Page 128 and 129: 2 Data Types All available formats
- Page 130 and 131: 2 Data Types Integer Functions Func
- Page 132 and 133: 2 Data Types Infinity and NaN Funct
- Page 134 and 135: 2 Data Types 1 0 0 1 0 1 1 0 The MA
- Page 136 and 137: 2 Data Types A(B) ans = 5 15 30 35
- Page 138 and 139: 2 Data Types Characters and Strings
- Page 140 and 141: 2 Data Types name = ['Thomas R. Lee
- Page 142 and 143: 2 Data Types Phoenix length(strings
- Page 144 and 145: 2 Data Types • “Setting Field W
1 Data Structures<br />
Summary of Matrix and Array Functions<br />
This section summarizes the principal functions used in creating and handling<br />
matrices. Most of these functions work on multidimensional arrays as well.<br />
FunctionstoCreateaMatrix<br />
Function<br />
[a,b] or [a;b]<br />
accumarray<br />
blkdiag<br />
cat<br />
diag<br />
horzcat<br />
magic<br />
ones<br />
rand<br />
repmat<br />
vertcat<br />
zeros<br />
Description<br />
Create a matrix from specified elements, or concatenate<br />
matrices together.<br />
Construct a matrix using accumulation.<br />
Construct a block diagonal matrix.<br />
Concatenate matrices along the specified dimension.<br />
Create a diagonal matrix from a vector.<br />
Concatenate matrices horizontally.<br />
Create a square matrix with rows, columns, and<br />
diagonals that add up to the same number.<br />
Create a matrix of all ones.<br />
Create a matrix of uniformly distributed random<br />
numbers.<br />
Create a new matrix by replicating or tiling another.<br />
Concatenate two or more matrices vertically.<br />
Create a matrix of all zeros.<br />
Functions to Modify the Shape of a Matrix<br />
Function<br />
ctranspose<br />
flipdim<br />
fliplr<br />
Description<br />
Flip a matrix about the main diagonal and replace each<br />
element with its complex conjugate.<br />
Flip a matrix along the specified dimension.<br />
Flip a matrix about a vertical axis.<br />
1-72