How to Create an Empty Matrix in MATLAB
-
Use the
ones()
Function to Create an Empty Matrix in MATLAB -
Use the
zeros()
Function to Create an Empty Matrix in MATLAB -
Use the
eye()
Function to Create an Empty Matrix in MATLAB
We will look at different ways to create an empty matrix in MATLAB.
We will use different example codes and related outputs to clear your concepts and give you a complete insight using MATLAB.
We use the matrix-algebra
method to easily calculate complex and lengthy formulas in MATLAB. Matrix is a rectangular array that contains any data we enter and organize according to our requirements.
The vertical entries of our data fill the columns of a matrix, whereas the horizontal data entries in our matrix are known as rows. An empty matrix
has at least one dimension equal to zero.
The smallest empty matrix has dimensions (m-by-n) 0-by-0
. We use the square brackets []
without any data or value inserted in it to create our desired 0-by-0
matrix:
Use the ones()
Function to Create an Empty Matrix in MATLAB
The ones()
function, in MATLAB, is used to create a matrix containing all ones as data. We also can use this function to create an empty matrix of any size.
We pass the order of the matrix we want, and the output displays the required matrix. See example,
%Suppose our matrix is following:
matrix=ones(0,3)
Output:
matrix = 0×3 empty double matrix
This example used the ones()
function to create an mxn
sized empty double matrix.
Use the zeros()
Function to Create an Empty Matrix in MATLAB
The function zeros()
returns a matrix with all values as 0
. By an empty or null matrix, if we mean a matrix having all values as 0
, the zeros()
function comes in handy.
%Suppose our matrix is following:
matrix = zeros(3,5)
Output:
matrix =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
We created a size 3-by-5
matrix using the function zeros()
in this example.
The null/empty matrix containing all zeros has one of the major applications in digital image processing.
Add padding of zeros around our image to protect the boundary pixels from being cropped out due to different operations on the image.
Use the eye()
Function to Create an Empty Matrix in MATLAB
The eye()
function represents the identity function, but we can use this function to create an empty matrix in MATLAB.
%Suppose our matrix is following:
matrix=eye(0)
Output:
matrix = []
Note that we got an empty matrix of order 1-by-1
in the output, represented as the square brackets with nothing in them.
Mehak is an electrical engineer, a technical content writer, a team collaborator and a digital marketing enthusiast. She loves sketching and playing table tennis. Nature is what attracts her the most.
LinkedIn