补充内容 Programming with MATLAB
Programming with MATLAB 补充内容:
Introduce MATLAB is a high-level language that includes matrix-based data structures, its own internal data types, an extensive catalog of functions, an environment in which to develop your own functions and scripts, the ability to import and export to many types of data files, object-oriented programming capabilities, and interfaces to external technologies such as COM, Java, programs written in C and Fortran, and serial port devices
Introduce MATLAB® is a high-level language that includes matrix-based data structures, its own internal data types, an extensive catalog of functions, an environment in which to develop your own functions and scripts, the ability to import and export to many types of data files, object-oriented programming capabilities, and interfaces to external technologies such as COM, Java, programs written in C and Fortran, and serial port devices
Introduce This lecture presents the MATLAB programming features and techniques in the following chapters ● Data Structures ● Data Types O Basic Program Components M-File Programming
Introduce This lecture presents the MATLAB programming features and techniques in the following chapters: ⚫Data Structures. ⚫Data Types. ⚫Basic Program Components. ⚫M-File Programming
Data Structures The most basic data structure in MATLAB is the matrix MATLAB uses these two-dimensional matrices to store single numbers and linear series of numbers as well. In these cases, the dimensions are 1-by-1 and 1-by-n respectively, where n is the length of the numeric series MATLAB also supports data structures that have more than two dimensions These data elements can be numbers characters logical states of true or false, or even other MATLAB structure types
Data Structures MATLAB uses these two-dimensional matrices to store single numbers and linear series of numbers as well. In these cases, the dimensions are 1-by-1 and 1-by-n respectively, where n is the length of the numeric series. The most basic data structure in MATLAB® is the matrix. These data elements can be numbers, characters, logical states of true or false, or even other MATLAB structure types. MATLAB also supports data structures that have more than two dimensions
1-1 Creating Matrice Method 1: Constructing a Simple matrix The simplest way to create a matrix in MATLAB is to use the matrix constructor operator, [ Create a row in the matrix by entering elements(shown as E below) within the brackets. Separate each element with a comma or space roW=[E1,E2,…,.m] roW=[E1E2…Em
1-1 Creating Matrice The simplest way to create a matrix in MATLAB is to use the matrix constructor operator, []. Create a row in the matrix by entering elements (shown as E below) within the brackets. Separate each element with a comma or space: row = [E1, E2, ..., Em] row = [E1 E2 ... Em] Method 1: Constructing a Simple Matrix
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