logo

Matrix Size and Related Functions in MATLAB 📂Programing

Matrix Size and Related Functions in MATLAB

Functions

  • size(): Returns a row vector that contains the lengths of the rows and columns of the matrix.
    It is useful for creating a zero matrix of the same size as the matrix being dealt with.

  • zeros(size(A)): Returns a zero matrix of the same size as A.

  • length(): Returns the larger number among the rows and columns.
    In the case of row vectors and column vectors, it is the same as the number of elements, so numel() is the same. Also, since size() returns the size of the rows and columns, length(A)=max(size(A)).

  • numel(): Returns the number of elements of the matrix.

Example code and output are as follows.

A=[1 2 3];
B=[1 2 3 4 ; 2 3 4 1 ; 3 4 1 2];
C=zeros(3,8);

a=size(A)
b=size(B)
c=size(C)

d=length(A)
e=length(B)
f=length(C)

g=numel(A)
h=numel(B)
i=numel(C)

2019-09-1814;47;19\_.png