Operation of 1.MATLAB
This is a description of the operators in MATLAB. There are arithmetic operators, relational operators, and logical operators, respectively.
Table 3.1 Arithmetic operators
Operator |
Description |
Operator |
Description |
+ |
Addition |
.\ |
Left Division |
- |
Subtraction |
\ |
Matrix Left Division |
.* |
Multiplication |
.^ |
exponentiation |
* |
Matrix multiplication |
^ |
Matrix exponentiation |
./ |
Right Division |
.‘ |
Transpose |
/ |
Matrix Right Division |
‘ |
Matrix to rank, complex to conjugate |
Table 3.2 Relational operators
Operator |
Description |
Function |
< |
Less than |
Lt (A, B) |
<= |
Less than or equal |
Le (A, B) |
> |
Greater than |
GT (A, B) |
>= |
Greater than or equal |
GE (A, b) |
== |
Constant equals |
EQ (A, B) |
~= |
Not equal to |
NE (a) |
Table 3.3 logical operators and Function tables
Operator |
Description |
Function |
& |
and arithmetic |
and (A, B) |
| |
or arithmetic |
Or (A, B) |
~ |
Non-operational |
Not (a) |
Xor |
XOR or |
XOR (A, B) |
Matrix of 2.MATLAB
Table 3.4 Constructing a special matrix function table
Function |
Description |
Ones (n); Ones (N,m) |
Create a matrix with 1 elements |
Zeros (n); Zeros (n,m) |
Create a matrix with 0 elements |
Eye (n); Eye (N,m) |
Create a matrix with a diagonal element of 1 and all other elements as 0 |
Diag (v); Diag (X); Diag (V,K); Diag (X,k) |
Turns a vector into a diagonal matrix, or a diagonal element of a matrix |
Magic (N) |
Build a square so that each row, column, and diagonal elements are equal |
RAND (n); Rand (N,M) |
Create a uniformly distributed random matrix with an element value between 0 and 1 |
RANDN (n); RANDN (N,M) |
Establish a random matrix of standard normal distribution |
Randperm (N) |
Set up a randomly arranged vector of the specified integers |
Table 3.5 Matrix Merge function table
Function |
Description |
Cat (Dim,a,b) |
Merges A and b matrices in the specified direction dim, and if Dim=1 is a horizontal merge, dim=2 is vertically merged |
Horzcat (A, B) |
Horizontal Merge Matrix |
Vertcat (A, B) |
Vertical Merge Matrix |
Repmat (A,m,n) |
Copy the matrix and merge it into a new matrix |
Blkdiag (A, B) |
Known matrices merged into diagonal matrices |
(1) Example: Using Functions Repmat () and Blkdiag () to create matrices
Close all; Clear all; clc;% Close all graphics windows, clear all variables in the workspace, empty command line A=eye (3); B=rand (3); C1=repmat (a,2,3);% copies the matrix into a new matrix C2=blkdiag (A, b);% merges matrices into diagonal matrices
Run results
(2) Example: Matrix A split to re-establish matrix
Close all; Clear all; clc;% Close all graphics windows, clear all variables in the workspace, empty command line A=magic (5); B=a (:, [2 4]);% extracts the 2nd and 4th columns of matrix A matrix bc=a ([1 3],[2 4]);% extracts the 1th and 3rd rows in matrix A, the 2nd column and the 4th column elements constitute the matrix cd=a (1:3,3:4);% extracts 1 to 3 rows in matrix A, The elements in the 3 to 4 columns form the new matrix De=a ([1:3;4 5 7;10:12]); The element with the single subscript 1 to 3 in matrix A is the first row, the element labeled 4,5,7 is the second row, the subscript is 10 to 12, and the third row is the matrix E
(3) Determinant of Phalanx: det ()
(4) Matrix transpose Matrix: Transpose ()
(5) Inverse matrix: Inv (A); Pseudo-Inverse matrix: PINV (B)
[If the matrix is not a square, or a square with a non-full rank, the matrix has no inverse matrix, but the pseudo-matrix can be obtained ]
(6) Rank of matrix: rank ()
3.MATLAB Control Statements
(1) For statement
For loop control variable = expression 1: Expression 2: Expression 3 statement end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for loop control variable = array expression statement end
(2) While statement
While-relational expression statement end
(3) If statement
If expression statement 1 Else statement 2 end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% If expression 1 statement 1 ElseIf Expression 2- statement 2 ... ElseIf expression n statement n Else statement n+1 End
(4) Switch statement
Switch expression case expression 1 statement 1 case expression 2 statement 2 ... CASE expression N statement n Otherwise statement n+1 End
(5) Try statement: Error Capture statement
Try statement 1 catch statement 2 End
(6) Break statement: You can jump out of the loop from this loop body, execute the closing sentence end of the next statement.
(7) Return statement: Terminates the run of the called function and returns to the calling function.
(8) Pause statement: If the call format is pause, the program is paused, press any key to continue, or pause (n), the program pauses for n seconds, and the call format is pause on/off, allowing/prohibiting subsequent programs to pause.
(9) Continue statement: can end this cycle, will skip the subsequent loop body statement, the next cycle.
Basic MATLAB (3)