1-1 Creating Matrice For example, to create a one row matrix of five elements, type A=[126293-822] A=[126293-822;162874391;-417-72956 A 126293-822 162874391 417-72956 Note that all rows must have the same number of elements
1-1 Creating Matrice A = 12 62 93 -8 22 16 2 87 43 91 -4 17 -72 95 6 For example, to create a one row matrix of five elements, type A = [12 62 93 -8 22]; Note that all rows must have the same number of elements. A = [12 62 93 -8 22; 16 2 87 43 91; -4 17 -72 95 6]
1-1 Creating Matrice Method 2: Specialized Matrix Functions MATLAB has a number of functions that create different kinds of matrices. Some create specialized matrices like the hankel or vandermonde matrix The functions shown in the table below create a matrices for more general use
1-1 Creating Matrice MATLAB has a number of functions that create different kinds of matrices. Some create specialized matrices like the Hankel or Vandermonde matrix. Method 2: Specialized Matrix Functions The functions shown in the table below create a matrices for more general use
Function Description ones Create a matrix or array of all ones zeros Create a matrix or array of all zeros eve Create a matrix with ones on the diagonal and zeros elsewhere accumarray Distribute elements of an input matrix to specified locations in an output matrix also allowing for accumulation diag Create a diagonal matrix from a vector magIc Create a square matrix with rows, columns, and diagonals that add up to the same number rand Create a matrix or array of uniformly distributed random numbers randn Create a matrix or array of normally distributed random numbers and arrays randperm Create a vector(1-by-n matrix)containing a random permutation of the specified integers
Function Description ones Create a matrix or array of all ones. zeros Create a matrix or array of all zeros. eye Create a matrix with ones on the diagonal and zeros elsewhere. accumarray Distribute elements of an input matrix to specified locations in an output matrix, also allowing for accumulation. diag Create a diagonal matrix from a vector. magic Create a square matrix with rows, columns, and diagonals that add up to the same number. rand Create a matrix or array of uniformly distributed random numbers. randn Create a matrix or array of normally distributed random numbers and arrays. randperm Create a vector (1-by-n matrix) containing a random permutation of the specified integers
The first example is A= zeros(1, 6) A 0 0 0 The second example is magic that create a magic Square Matrix A= magic(5) A 17241815 23571416 46132022 101219213 11182529
The first example is A = zeros(1, 6) A = 0 0 0 0 0 0 The second example is magic that create a Magic Square Matrix. A = magic(5) A = 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
1-1 Creating Matrice Method 3: Concatenating Matrices Matrix concatenation is the process of joining one or more matrices to make a new matrix. The brackets l operator discussed earlier in this section serves not only as a matrix constructor, but also as the MATLAB concatenation operator The expression C=[AB] horizontally concatenates matrices A and B. The expression C= [A; B] vertically concatenates them
1-1 Creating Matrice The expression C = [A B] horizontally concatenates matrices A and B. The expression C = [A; B] vertically concatenates them. Method 3: Concatenating Matrices Matrix concatenation is the process of joining one or more matrices to make a new matrix. The brackets [] operator discussed earlier in this section serves not only as a matrix constructor, but also as the MATLAB concatenation operator