Matlab gets matrix size, number of rows, number of columns, total number of elements——size()/length()/numel()

1 size()

size: Get the number of rows and columns of the array

  1. s=size(A), when there is only one output parameter, returns a row vector, the first element of the row vector is the number of rows of the array, and the second element is the number of columns of the array.
  2. [r,c]=size(A), when there are two output parameters, the size function returns the number of rows of the array to the first output variable and the number of columns of the array to the second output variable.
  3. If you add another item to the input parameter of the size function and assign 1 or 2 to the item, size will return the number of rows or columns of the array. Where r=size(A,1) the statement returns the number of rows of array A, c=size(A,2) the statement returns the number of columns of array A.
  4. n=max(size(A): If A is a non-empty array, return the maximum dimension of A; if A is an empty array, return the longest non-zero dimension in A.

2 length()

length: the length of the array (ie, the greater of the number of rows or the number of columns)

n=length(A): If A is a non-empty array, return the larger value between the number of rows and the number of columns, which is equivalent to executing max(size(A)); if A is an empty array , returns 0; if A is a vector, returns the length of A.

3 name()

numel: total number of elements.

n=numel(A) This statement returns the total number of elements in the array.    

Guess you like

Origin blog.csdn.net/qixun7099/article/details/129047748