next Creating a sinusoid
up Music 270a: Matlab Tutorial 2
previous Creating functions


Loops and Conditional Statements

As in all programming languages, Matlab can be used to repeat statements for a specific number of times--or until a condition has been reached--by using the for or while loops.

N = 10;

for n = 1:N
  for m = 1:N
    a(n,m) = 1/(n+m+1);
  end
end

Conditional operators like if and switch are also available. Call a help on these operators for more information.


next Creating a sinusoid
up Music 270a: Matlab Tutorial 2
previous Creating functions

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

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