next Vector Operations
up Music 270a: Matlab Tutorial 1
previous Variables


Vectors and Matrices

A vector is a sequence of numbers. Vectors will be particularly important to us because that is how sound is represented, as a sequence of numbers. Try the following to see how the comma and semicolon change the output:

>> x = [1 3 7 15]
>> x = [1, 3, 7, 15]
>> x = [1; 3; 7; 15]
>> x'

In the last example, we see the transpose operator. We will see this more later, but for now you can use this to turn row vectors into column vectors and vice versa.

Some other useful ways to create vectors:

>> 1:5
>> z = 1:1/2:5
>> ones(1, 5)
>> zeros(1, 5)

You can determine the length and size of a vector using the following commands:

>>length(x)
>>size(x)

Accessing values within a vector:

>> x(3)
>> x(1:3)
>> x(find(x==7))

You can concatenate two (or more) vectors as follows:

>> z = [1:3, 4:6]


next Vector Operations
up Music 270a: Matlab Tutorial 1
previous Variables

``Music 270a: Digital Audio Processing'' by Tamara Smyth, Department of Music, University of California, San Diego (UCSD).
Download PDF version (matlabtut1.pdf)
Download compressed PostScript version (matlabtut1.ps.gz)

Copyright © 2013-01-07 by Tamara Smyth.
Please email errata, comments, and suggestions to Tamara Smyth<trsmyth@ucsd.edu>