Column Vectors in MATLAB
Last Updated :
28 Feb, 2023
Column vectors are vectors that have a single column but, multiple rows. MATLAB provides various functions that use column vectors as their arguments. In this article, we will see different methods of creating and using column vectors in MATLAB.
Creating Column Vectors:
Method 1:
The simplest way of creating column vectors in MATLAB is by using the ‘;’ separator. See the example below.
Example 1:
Output:
This will create a column vector with 5 rows.
Method 2:
A column vector is the transpose of a row vector so, we can convert a row vector into a column vector by taking its transpose.
Example 2:
Matlab
vec = 3:13;
disp(vec)
vec = vec';
disp( "Transpose of row vector is:" )
disp(vec)
|
Output:
Uses of Column Vectors:
One of the uses of column vectors is for multiplying row vectors.
Consider the case when we are given two row vectors and we need to find their product. Since they are both row vectors, it is impossible to calculate their product as their dimensions are not compatible. So, we would change one of them to a column vector and then we can compute their product.
Example 3:
Matlab
vecA = 1:8;
vecB = 5:12;
vecB = vecB';
prod = vecB*vecA;
disp(prod)
|
Output:
Share your thoughts in the comments
Please Login to comment...