MATLAB Vectors - MATLAB

What is MATLAB Vectors?

A vector is a one-dimensional array of numbers. MATLAB allows creating two types of vectors −

  • Row vectors
  • Column vectors

Row Vectors

Row vectors are created by enclosing the set of elements in square brackets, using space or comma to delimit the elements.

MATLAB will execute the above statement and return the following result –

Column Vectors

Column vectors are created by enclosing the set of elements in square brackets, using semicolon to delimit the elements.



MATLAB will execute the above statement and return the following result –


Referencing the Elements of a Vector

You can reference one or more of the elements of a vector in several ways. The ith component of a vector v is referred as v(i). For example –



MATLAB will execute the above statement and return the following result –


When you reference a vector with a colon, such as v(:), all the components of the vector are listed.


MATLAB will execute the above statement and return the following result –



MATLAB allows you to select a range of elements from a vector.


For example, let us create a row vector rv of 9 elements, then we will reference the elements 3 to 7 by writing rv(3:7) and create a new vector named sub_rv.



MATLAB will execute the above statement and return the following result –

Vector Operations

In this section, let us discuss the following vector operations −

  • Addition and Subtraction of Vectors
  • Scalar Multiplication of Vectors
  • Transpose of a Vector
  • Appending Vectors
  • Magnitude of a Vector
  • Vector Dot Product
  • Vectors with Uniformly Spaced Elements

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MATLAB Topics