Introduction to Vectors in Matlab

This is the basic introduction to Matlab. Creation of vectors is included with a few basic operations.

Matlab is a software package that makes it easier for you to enter matrices and vectors, and manipulate them. The interface follows a language that is designed to look a lot like the notation use in linear algebra. In the following tutorial, we will discuss some of the basics of working with vectors.

To start matlab, open up a unix shell and type the command to start the software: matlab. This will start up the software, and it will wait for you to enter your commands. In the text that follows, any line that starts with two greater than signs (>>) is used to denote the matlab command line. This is where you enter your commands.

Almost all of Matlabs basic commands revolve around the use of vectors. To simplify the creation of vectors, you can define a vector by specifying the first entry, an increment, and the last entry. Matlab will automatically figure out how many entries you need and their values. For example, to create a vector whose entries are 0, 2, 4, 6, and 8, you can type in the following line:

>> 0:2:8

ans =

     0     2     4     6     8

Matlab also keeps track of the last result. In the previous example, a variable "ans" is created. To look at the transpose of the previous result, enter the following:
>> ans'

ans =

     0
     2
     4
     6
     8

To be able to keep track of the vectors you create, you can give them names. For example, a row vector v can be created:
>> v = [0:2:8]

v =

     0     2     4     6     8

>> v

v =

     0     2     4     6     8

>> v;
>> v'

ans =

     0
     2
     4
     6
     8



Note that in the previous example, if you end the line with a semi-colon, the result is not displayed. This will come in handy later when you want to use Matlab to work with very large systems of equations.

Matlab will allow you to look at specific parts of the vector. If you want to only look at the first three entries in a vector you can use the same notation you used to create the vector:


>> v(1:3)

ans =

     0     2     4

>> v(1:2:4)

ans =

     0     4

>> v(1:2:4)'

ans =

     0
     4


Once you master the notation you are free to perform other
operations:

>> v(1:3)-v(2:4)

ans =

    -2    -2    -2


The next tutorial covers the use of matrices.

This tutorial written by Kelly Black.