In Matlab you have to know which commonly used commands

April 04, 2023

Some commonly used commands in Matlab

Feeling a lot is really useful, share it!

First, the common object operation: In addition to the commonly used function keys of the general windows window.

1,! Dir can view the files in the current working directory. ! Dir& can be viewed in the dos state.

2, who can view the current workspace variable name, whos can view the variable name details.

3, function keys:

Function key shortcuts

Direction key Ctrl+P Return to the previous row

Direction down key Ctrl+N Return next line input

Left arrow Ctrl+B Cursor moves one character backward

Right arrow Ctrl+F cursor moves one character forward

Ctrl+Direction Right Ctrl+R Moves the cursor one character to the right

Ctrl+direction left Ctrl+L cursor left one character

Home Ctrl+A cursor to the beginning of the line

End Ctrl+E cursor moves to the end of the line

Esc Ctrl+U clear one line

Del Ctrl+D Clear the cursor

Backspace Ctrl+H Delete the previous character of the cursor

Ctrl+K to end of line

Ctrl+C interrupts the command being executed

4, clc can command the window display content, but does not clear the workspace.

In Matlab you have to know which commonly used commands

Second, the function and operation

1, the operator:

+: add, -: subtract, *: multiply, /: divide,: left divide ^: power, ': conjugate transpose of complex number, (): formulate operation sequence.

2, commonly used function table:

Sin( ) Sine (variable in radians)

Cot( ) Cotangent (variable in radians)

Sind( ) sine (variable in degrees)

Cotd( ) Cotangent (variable in degrees)

Asin( ) arcsine (return radians)

Acot( ) Anti-cotangent (return radian)

Asind( ) Arc Sine (Return Degrees)

Acotd( ) Anti-cotangent (return degrees)

Cos( ) cosine (variable is radians)

Exp( ) index

Cosd( ) cosine (variable in degrees)

Log( ) logarithm

Acos( ) residual sine (return radians)

Log10( ) base 10 logarithm

Acosd( ) residual sine (return degree)

Sqrt( ) prescribing

Tan( ) Tangent (variable in radians)

Realsqrt( ) returns non-negative root

Tand( ) Tangent (variable in degrees)

Abs( ) takes absolute value

Atan() Arc tangent (return radian)

Angle( ) returns the complex phase angle

Atand( ) Arc tangent (degrees returned)

Mod(x,y) returns the remainder of x/y

Sum () vector element summation

3. The remaining functions can be obtained with the help elfun and help specfun commands.

4, the value of commonly used constants:

Pi 3.1415926.......

Realmin minimum float, 2^-1022

i imaginary unit

Realmax maximum float, (2-eps)2^1022

j imaginary unit

Inf infinite value

Eps float relative longitude=2^-52

NaN null value

Third, the array and matrix:

1, the method of constructing an array: incremental hair and linspace (first, last, num) first and last as the start and end number, num is the number of array elements required.

2, the method of constructing the matrix: You can directly use [] to input the array, you can also use the following function to generate the matrix.

Ones( ) creates a matrix with all elements equal to 1, which can be dimensioned, 1,2... Variables

Zeros() creates a matrix with all elements 0

Eye() creates a matrix with 1 diagonal elements and 0 other elements

Diag() creates a diagonal matrix from the vector, ie, the elements of the vector are diagonal elements

Magic() Creates a Rubik's Cube

Rand() creates a random matrix, obeying uniform distribution

Randn() creates a random matrix, obeys a normal distribution

Randperm() creates random row vectors

Horcat C=[A,B], horizontal aggregation matrix, can also use cat(1,A,B)

Vercat C=[A;B], vertical aggregation matrix, also available with cat(2,A,B)

Repmat(M,v,h) aggregates matrix M in the vertical direction v times and aggregates h times in the horizontal direction

Blkdiag(A,B) Create block diagonal matrices with A, and B as blocks

Length returns the length of the longest dimension of the matrix

Ndims return dimensions

Numel Returns the number of matrix elements

Size returns the length of each dimension, [rows,cols]=size(A)

Reshape Reshapes the matrix, reshape(A,2,6), turns A into a matrix of 2&Times;6, arranged in columns.

Rot90 Rotate matrix 90 degrees counterclockwise

Fliplr flips the matrix along the vertical axis

Flipud flips the matrix along the horizontal axis

Transpose flips the matrix along the main diagonal

The ctranspose transpose matrix can also be A' or A.', which only differs when the matrix is ​​a complex matrix

The inverse of the inv matrix

The determinant value of the det matrix

The sum of the trace matrix diagonal elements

Norm The norm of a matrix or vector, norm(a,1), norm(a,Inf)...

Normest The largest norm vector of the matrix

Cholesky decomposition of chol matrix

Cholinc is not completely cholesky breakdown

Lu LU decomposition

Luinc Incomplete LU decomposition

Qr orthogonal decomposition

Kron(A,B) A is m&TImes;n, B is p&TImes;q, then a matrix of mp&Times;nq is generated. Each element of A is multiplied by B and occupies a space of size p*q.

Rank finds the thorns of the matrix

Pinv inverse inverse matrix

A^p operates on A

A.^P operates on each element in A

Fourth, numerical calculation

1. Solving linear equations

(1) The solution of AX=B can be found with X=AB. The solution of XA=B can be found with X=A/B. If A is a matrix of m×n, a unique solution can be found when m=n, mn, an overdetermined system, and at least one set of solutions is found. If A is singular and AX=B has a solution, we can use X=pinv(A)×B to return the least squares solution

(2) AX = b, A = L × U, [L, U] = lu (A), X = U (Lb), that is, LU solution.

(3) QR (orthogonal) decomposition is to represent a matrix as the product of an orthogonal matrix and an upper triangular matrix, A = Q × R [Q, R] = chol (A), X = Q (Ub)

(4) The cholesky decomposition is similar.

2, characteristic value

D=eig(A) returns a matrix of all eigenvalues ​​of A. [V,D]=eig(A) also returns the eigenvector matrix.

3, A = U × S × UT, [U, S] = schur (A). The diagonal element of S is the characteristic value of A.

4. The polynomials in the polynomial Matlab are represented by vectors. The specific operation functions are as follows:

Multiplication of conv polynomials

Division of deconv polynomials, [a,b]=deconv(s), return quotient and remainder

Poly Find the polynomial coefficient (coefficient of a polynomial by a known root)

Polyeig Find the polynomial eigenvalue

Polyfit(x,y,n) Polynomial curve fitting, where x,y is the fitted vector and n is the polynomial order of the fit.

Polyder finds the first derivative of the polynomial and polyder(a,b) returns the derivative of ab

[a,b]=polyder(a,b) returns the derivative of a/b.

Polyint polynomial integral

Polyval polynomial value

Polyvalm Finds the value of a polynomial as a matrix

Fractional fractional expansion

Roots Find the root of a polynomial (returns a vector of all roots)

Note: Use ploy(A) to find the characteristic polynomial of the matrix, and then find its root, which is the eigenvalue of the matrix.

5. Interpolation Common interpolation functions are as follows:

Griddata data grid compound surface fitting

Griddata3 3D Data Griding and Hypersurface Fitting

Interp1 one-dimensional interpolation (yi=interp1(x,y,xi,'method')Method=nearest/linear/spline/pchip/cubic

Interp2 two-dimensional interpolation zi=interp1(x,y,z,xi,yi'method'),bilinear

Interp3 three-dimensional interpolation

Interpft uses the Fast Fourier Transform for one-dimensional interpolation, help fft.

Mkpp uses piecewise polynomials

Spline cubic spline interpolation

Pchip segmented hermit interpolation

6, the function of the value of the solution

Fminbnd('f',x1,x2,optiset(,)) finds the minimum value of f between x1 and x2. The Optiset option can have 'Display'+'iter'/'off'/'final', which means that the calculation process is displayed/not displayed/only the final result is displayed. Fminsearch finds the minimum value of a multivariate function. Fzero('f',x1) finds the zero point of a one-variable function. X1 is the starting point. You can also use the above options.

Fifth, the image is drawn:

1, the basic drawing function

Plot plots two-dimensional linear graphs and two axes

Plot3 draws three-dimensional linear graphics and two axes

Fplot draws an image of a function in an interval. Fplot('f', area, line style, color)

Loglog plots a logarithmic graph and two axes (both coordinates are logarithmic) semilogx draws a semilogarithmic coordinate graph

Semilog plot semi-logarithmic coordinates

2, line type: color line type

y yellow. Dot line v Down arrow

g Green -. Combinations Right Arrow

b blue + point is a plus sign "Left arrow

m Red purple o Hollow circle p Pentagram

c Blue purple * Asterisk star Hexagonal

w White. Solid dots hold on Add graphics

r red x cross shape grid on to add a grid

k black s square - solid line

d Diamond - dashed line ^ up arrow

3. You can use subplot(3,3,1) to divide the drawing area into three rows and three columns. The first area is currently used. If you want to draw different graphics in a window at this time, you need to hold on.

Desktop Phone Holder

Desktop Phone Holder,Desktop Mobile Phone Holder,Adjustable Desktop Phone Holder,Universal Desktop Cell Phone Holder

Ningbo Luke Automotive Supplies Ltd. , https://www.car-phone-holder.com