English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Vectors are one-dimensional numeric arrays. MATLAB allows the creation of two types of vectors-
row vectors
column vector
row vectors are created by enclosing the set of elements in square brackets and delimiting elements with spaces or commas.
r = [7 8 9 10 11]
MATLAB will execute the above statement and return the following result-
r = 7 8 9 10 11
column vector by enclosing the set of elements in square brackets and separating elements with semicolons.
c = [7; 8; 9; 10; 11]
MATLAB will execute the above statement and return the following result-
c = 7 8 9 10 11
You can reference one or more elements of a vector in various ways. The i-th element of vector v isaThe components are called v(i). For example-
v = [ 1; 2; 3; 4; 5; 6]; % create a column vector by6a column vector of v(3)
MATLAB will execute the above statement and return the following result-
ans = 3
When referencing a colon vector, such as v(:), it will list all the components of the vector.
v = [ 1; 2; 3; 4; 5; 6]; % creating a column vector of 6 elements v(:)
MATLAB will execute the above statement and return the following result-
ans = 1 2 3 4 5 6
MATLAB allows you to select a series of elements from a vector.
For example, let's create a vector containing9a row vector ofrv, then we will refer to the elements by writing3to7,rv(3:7)and create a namedsub_rvto create a new vector.
rv = [1 2 3 4 5 6 7 8 9]; sub_rv = rv(3:7)
MATLAB will execute the above statement and return the following result-
sub_rv = 3 4 5 6 7
In this section, let's discuss the following vector operations-