MATLAB vectors represent one-dimensional arrays of numerical values, allowing the creation of two fundamental types:
- Row Vectors.
- Column Vectors.
Row Vectors in MATLAB
Row vectors in MATLAB are formed by enclosing a set of elements within square brackets, using spaces or commas to separate individual elements.
For example:
r = [7 8 9 10 11]
Executing the given command in MATLAB yields the following result:
Column Vectors in MATLAB
Column vectors in MATLAB are created by enclosing a set of elements within square brackets, using semicolons to separate individual elements.
For example:
c = [7; 8; 9; 10; 11]
Executing the given command in MATLAB produces the following result:
Referencing Vector Elements in MATLAB
You can reference one or multiple elements of a vector in MATLAB in various ways. The ith element of vector v is denoted as v(i).
For example:
v = [ 1; 2; 3; 4; 5; 6]; % create a column vector with 6 elements.
v(3)
Executing the given command in MATLAB yields the following result:
ans = 3
When referencing a vector using a colon (:), all elements of the vector are enumerated.
For example:
v = [ 1; 2; 3; 4; 5; 6]; % create a column vector with 6 elements.
v(:)
Executing the given command in MATLAB produces the following result:
MATLAB enables you to select a range of elements from a vector.
For example, create a vector vr with 9 elements, then reference elements 3 to 7 using rv(3:7) and create a new vector named sub_rv.
rv = [1 2 3 4 5 6 7 8 9];
sub_rv = rv(3:7)
Executing the given command in MATLAB produces the following result:
Vector Operations
Vector Operations in MATLAB
Here are some vector operations in MATLAB:
- Addition, subtraction of vectors in MATLAB.
- Dot product of vectors.
- Transforming a vector.
- Concatenating vectors.
- Calculating the magnitude of a vector.
In essence, you can broadly perceive a Vector in MATLAB as a one-dimensional array of numerical values. There are two fundamental vectors in MATLAB: the column vector and the row vector.
If your MATLAB software faces a license expiration, you can renew your MATLAB license annually to extend your usage time and continue learning with MATLAB. Wishing you success!