This article will walk through the ways of creating a row or column vector of zeros in MATLAB.
What is a Vector of Zeros? Why is it Useful to Create a Vector of Zeros in MATLAB?
The vector of zeros is a vector consisting of all zero values. Creating a vector of zeros is important in MATLAB because it can be used for varieties of ways, such as:
- To initialize variables to all zeros
- To represent the set of unknown values
- To represent a matrix of zeros
How to Produce a Zeros’ Vector in MATLAB?
The zeros() function is MATLAB’s built-in function that can be utilized to generate a zeros vector. The function takes two arguments as input: the rows’ number and the columns’ number. If the number of rows is set to 1, the function will create a row vector of zeros. If the number of columns is set to 1, the function will create a column vector of zeros.
Syntax
The syntax of the zeros() function for creating a row or column vector of zeros in MATLAB is given below:
zeros(n,1)
Here,
The function zeros(1,n) create a row vector of zeros, while zeros(n,1) create a column vector having all zero elements.
Return Value
This function takes an array’s size as input and returns an array having all zero entries.
Example 1: How to Generate a Row Vector of Zeros in MATLAB?
This example shows how to create a row vector of zeros in MATLAB using the zeros(1, n) function.
Example 2: How to Generate a Zeros Column Vector in MATLAB?
In this example, we create a column vector of zeros having a length 9-by-1 using the zeros(n,1) function in MATLAB.
Example 3: How to Create a Vector of Zeros in MATLAB By Specifying the Vector Type?
We can also create a vector of zeros in MATLAB by specifying the vector type that could be double, single, int8, uint8, int16, uint16, and more. The following example will create a column vector of zeros of type int16.
Conclusion
MATLAB is a robust programming language that allows us to create vectors, matrices, and arrays using various built-in functions. One such function is the zeros() function which allows us to create a vector of zeros of the specified size. This guide has provided an easy guide to creating a vector of zeros using MATLAB’s zeros() function. The examples provided in this guide will help you create a row or column vector of zeros in MATLAB.