Summary of commonly used functions in MATLAB

Commonly used functions in MATLAB

1. The zeros() function and ones() function in matalab

The zeros() function is used to generate a matrix of all 0s and the
ones() function is used to generate a matrix of all 1s

1. The specific usage of zeros() function is as follows:

zeros(n): n n all-zero matrix
zeros(m,n): m
n all-zero matrix
zeros(d1,d2,d3……dn): generate d1 d2 d3*……*dn all-zero matrix or array.
zeros(size(A)): Generate an all-zero matrix with the same size as matrix A.

2. The specific usage of the ones() function is as follows:

ones(n): n n all 1 matrix
ones(m,n): m
n all 1 matrix
ones(d1,d2,d3……dn): generate d1 d2 d3*……*dn all 1 matrix or array.
ones(size(A)): Generate a matrix of all ones with the same size as matrix A.

2. The size() function in matlab

Usage of the size() function:
size(A): For matrix A, the function size(A) returns a row of vectors.
The first element of the row vector represents the row of the matrix, and the second element represents the column of the matrix.
size(A, 1): represents the number of rows of matrix A
size(A, 2): represents the number of columns of matrix A
3. The sum() function in matlab

Usage of sum() function:

For sum(A),
if A is a row vector , do not specify dim or specify dim as 2, namely sum(A) or sum(A, 2), the result is the sum of all elements of the row vector;
if dim is specified as 1 , The calculation result is a row vector , and the row vector is the same as the original row vector.

Guess you like

Origin blog.csdn.net/aqiuisme/article/details/108890702