Basic defining a vectors in Matlab---Matlab Tutorials

When we talk a bout basics of vectors we noramally remember few basic operations

Defining a vector
Accesing elements
Basic operations that can be performed on vectors
Defining a vector

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.

If you are running windows or Mac OSX, you can start matlab by choosing it from the menu. To start matlab on a unix system, 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 Matlab's basic commands revolve around the use of vectors. A vector is defined by placing a sequence of numbers within square braces:

>> v = [3 1]
v =
3 1
This creates a row vector which has the label "v". The first entry in the vector is a 3 and the second entry is a 1. Note that matlab printed out a copy of the vector after you hit the enter key. If you do not want to print out the result put a semi-colon at the end of the line:
>> v = [3 1];

If you want to view the vector just type its label:
>> v
v =
3 1

You can define a vector of any size in this manner:

>> v = [3 1 7 -21 5 6]
v =

3 1 7 -21 5 6

Notice, though, that this always creates a row vector. If you want to create a column vector you need to take the transpose of a row vector. The transpose is defined using an apostrophe ("'"):

>> v = [3 1 7 -21 5 6]'
v =

A common task is to create a large vector with numbers that fit a repetitive pattern. Matlab can define a set of numbers with a common increment using colons. For example, to define a vector whose first entry is 1, the second entry is 2, the third is three, up to 8 you enter the following:
>> v = = [1:8]
v =

1 2 3 4 5 6 7 8

If you wish to use an increment other than one that you have to define the start number, the value of the increment, and the last number. For example, to define a vector that starts with 2 and ends in 4 with steps of .25 you enter the following:
>> v = [2:.25:4]
v =

Columns 1 through 7
2.0000 2.2500 2.5000 2.7500 3.0000 3.2500 3.5000

Columns 8 through 9
3.7500 4.0000

No comments:

Top Blogs