Practice with Vectors
So far, you've learned some fundamental operations to create and work with vectors. In this live script, you'll
review earlier concepts and learn new vector operations. The activities are divided into the following sections:
Table of Contents
Creating Vectors.......................................................................................................................................................1
Concatenation.......................................................................................................................................................1
Vectors with Set Spacing......................................................................................................................................2
Vectors with Set Number of Elements.................................................................................................................. 3
Summary.............................................................................................................................................................. 3
Accessing and Manipulating Vector Elements..........................................................................................................3
Vector Indexing.....................................................................................................................................................3
Vector Manipulation.............................................................................................................................................. 4
Math Operations with Vectors...................................................................................................................................4
Arithmetic Operations...........................................................................................................................................4
Math Functions.....................................................................................................................................................5
Vector Characteristics...............................................................................................................................................6
Transpose.............................................................................................................................................................6
Size and Length....................................................................................................................................................6
Conclusion................................................................................................................................................................7
Creating Vectors
There are many ways to create vectors. In this section, you will see how to
• Create vectors using concatenation.
• Create vectors with a set spacing.
• Create vectors with a set number of elements.
Concatenation
Square brackets are used to group elements together into vectors. Use a space between elements to create a
row vector, or add a semicolon between elements to create a column vector.
rowVector = [1 3 6 3 11] % Row vector
colVector = [1; 3; 6; 3; 11] % Column vector
Use concatenation to create a column vector v1 with the following elements: 0, 1, 1, 0.
v1=[0; 1; 1; 0]
1