MATLAB Tutorial: Understanding Vectors, Referencing Elements, and Vector Operations, Cheat Sheet of Mathematics

A comprehensive tutorial on matlab vectors, including how to create row and column vectors, reference vector elements, and perform vector operations such as addition, subtraction, scalar multiplication, transpose, appending, and magnitude. It also covers vector dot product and vectors with uniformly spaced elements.

Typology: Cheat Sheet

2020/2021

Uploaded on 11/04/2021

ahmedsallam
ahmedsallam 🇪🇬

5 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
10/31/21, 4:21 PM
MATLAB - Vectors
https://www.tutorialspoint.com/matlab/matlab_vectors.htm
1/3
MATLAB - Vectors
MATLAB - Vectors
A vector is a one-dimensional array of numbers. MATLAB allows creating two types of vectors
A vector is a one-dimensional array of numbers. MATLAB allows creating two types of vectors −
Row vectors
Row vectors
Column vectors
Column vectors
Row Vectors
Row Vectors
Row vectors
Row vectors are created by enclosing the set of elements in square brackets, using space or
are created by enclosing the set of elements in square brackets, using space or
comma to delimit the elements.
comma to delimit the elements.
r
r =
=
[
[7
7
8
8
9
9
10
10
11
11]
]
MATLAB will execute the above statement and return the following result
MATLAB will execute the above statement and return the following result −
r =
r =
7 8 9 10 11
7 8 9 10 11
Column Vectors
Column Vectors
Column vectors
Column vectors are created by enclosing the set of elements in square brackets, using semicolon
are created by enclosing the set of elements in square brackets, using semicolon
to delimit the elements.
to delimit the elements.
c
c =
=
[
[7
7;
;
8
8;
;
9
9;
;
10
10;
;
11
11]
]
MATLAB will execute the above statement and return the following result
MATLAB will execute the above statement and return the following result −
c =
c =
7
7
8
8
9
9
10
10
11
11
Referencing the Elements of a Vector
Referencing the Elements of a Vector
Live Demo
Live Demo
Live Demo
Live Demo
pf3

Partial preview of the text

Download MATLAB Tutorial: Understanding Vectors, Referencing Elements, and Vector Operations and more Cheat Sheet Mathematics in PDF only on Docsity!

MATLAB - Vectors

MATLAB - Vectors

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

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

Row vectors

Row vectors

Column vectors Column vectors

Row Vectors Row Vectors

Row vectorsRow vectors are created by enclosing the set of elements in square brackets, using space orare created by enclosing the set of elements in square brackets, using space or

comma to delimit the elements.

comma to delimit the elements.

r

r

[

[

]

]

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

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

r =r =

Column Vectors Column Vectors

Column vectorsColumn vectors are created by enclosing the set of elements in square brackets, using semicolonare created by enclosing the set of elements in square brackets, using semicolon

to delimit the elements.

to delimit the elements.

c

c

[

[

]

]

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

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

c =c =

Referencing the Elements of a Vector Referencing the Elements of a Vector

Live Demo

Live Demo

Live Demo

Live Demo

You can reference one or more of the elements of a vector in several ways. The i

You can reference one or more of the elements of a vector in several ways. The i

component of a

component of a

vector v is referred as v(i). For example −

vector v is referred as v(i). For example −

v

v

[

[

];

];

creating a column vector

creating a column vector of

of 6

elements

elements

v

v (

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

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

ans =ans = 33

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

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

v

v

[

[

];

];

creating a column vector

creating a column vector of

of 6

elements

elements

v v(:)(:)

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

ans =

ans =

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

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

For example, let us create a row vector

For example, let us create a row vector

rv

rv

of 9 elements, then we will reference the elements 3 to 7

of 9 elements, then we will reference the elements 3 to 7

by writing

by writing

rv(3:7)

rv(3:7)

and create a new vector named

and create a new vector named

sub_rv

sub_rv

rv

rv

[

[

];

];

sub_rv

sub_rv

rv

rv (

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

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

sub_rv =sub_rv =

Vector Operations Vector Operations

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

th

th

Live Demo

Live Demo

Live Demo Live Demo

Live Demo

Live Demo