MATLAB NOTES To create a matrix that has multiple rows, separate the rows with semicolons. >> a = [1 2 3; 4 5 6; 7 8 10] a = 1 2 4 5 3 6 7 8 10 Another way to create a matrix is to use a function, such as ones, zeros, or rand. For example, create a 5-by-1 column vector of zeros. >> z = zeros(5,1) z = 0 0 0 0 0 >> z = ones(5,2) z = 1 1 1 1 1 1 1 1 1 1 >> z = rand(5,3) z = 0.8147 0.0975 0.1576 0.9058 0.2785 0.9706 0.1270 0.5469 0.9572 0.9134 0.9575 0.4854 0.6324 0.9649 0.8003 To transpose a matrix, use a single quote ('): >> a' ans = 1 4 7 2 5 8 3 6 10 >> a + 10 4 ans = 11 12 13 14 15 16 17 18 20 To perform element-wise multiplication rather than matrix multiplication, use the .* operator: >> p = a.*a p = 1 4 9 16 25 36 49 64 100 To perform Natural Matrix multiplication, use the * operator: >> a * a ans = 30 36 45 66 81 102 109 134 169 MATLAB NOTES Concatenation >> A = [a,a] A = 1 2 3 1 2 3 4 5 6 4 5 6 7 8 10 7 8 10 >> A = [a; a] A = 1 2 3 4 5 6 7 8 10 1 2 3 4 5 6 7 8 10 When you want to access selected elements of an array, use indexing. >> a(2,2) ans = 5 5 MATLAB NOTES use a single subscript that traverses down each column in order: >> a(6) ans = 8 The colon operator also allows you to create an equally spaced vector of values using the form start:step:end. >> b = 0:20:200 b = 0 20 40 60 80 100 120 140 160 180 200 sqrt(X) is the square root of the elements of X. Complex results are produced if X is not positive. >> sqrt((-2:2)')