varName = expression
can't be a keyword
Note: MATLAB does syntax highlighting
be descriptive
don't use a name already in use
a = 2 : 7 b = [ 1 : 2 : 11 ] c = -4 : 3 : 10 d = 10 : 2 : 1 e = [ c , a ]
vec = [ 5 2 1 6 3 ] vec(1, 3) = 4 vec(8) = 9 vec(2:4) = -1
Change the values at the even indices vec to 7
Determine how long a vector is (i.e., how many elements it has)
mat = [ 11:15 ; 21:25 ; 31:35 ] mat( 1, : ) mat( [ 1 2 ], 3 ) mat( [ 2 3 1 ], [ 4 1 5 ] )
All the rows and the odd-numbered columns?
How many rows and columns?
script = stored sequence of MATLAB commands, also called a program or an M-file
Suppose we've written a script and saved it in tester.m. To run it from the Command Window:
>>