Presentation is loading. Please wait.

Presentation is loading. Please wait.

MatlABBA. The Colon Operator (1) This is one MatLab’s most important operators 1:10 means the vector –1 2 3 4 5 6 7 8 9 10 100:-7:50 –100 93 86 79 72.

Similar presentations


Presentation on theme: "MatlABBA. The Colon Operator (1) This is one MatLab’s most important operators 1:10 means the vector –1 2 3 4 5 6 7 8 9 10 100:-7:50 –100 93 86 79 72."— Presentation transcript:

1 matlABBA

2 The Colon Operator (1) This is one MatLab’s most important operators 1:10 means the vector –1 2 3 4 5 6 7 8 9 10 100:-7:50 –100 93 86 79 72 65 58 51 0:pi/4:pi –0 0.7854 1.5708 2.3562 3.1416

3 The Colon Operator (2) The first K elements in the jth column is –A(1:K, j) Sum(A(1:4, 4)) is the sum of the 4th column or Sum(A(:, 4)) means the same

4 Deleting Rows and Columns (1) Create a temporary matrix X X=A; X(:, 2) = [] Deleting a single element won’t result in a matrix, so the following will return an error X(1,2) = []

5 Deleting Rows and Columns (2) However, using a single subscript, you can delete –a single element –sequence of elements So X(2:2:10) = [] gives x = 16 9 2 7 13 12 1

6 The ‘FIND’ Command (1) >> x = -3:3 x = -3 -2 -1 0 1 2 3 K = find(abs(x) > 1) K = 1 2 6 7

7 The ‘FIND’ Command (2) A = [ 1 2 3 ; 4 5 6 ; 7 8 9] [i, j] = find (A > 5) i = 3 2 3 j = 1 2 3

8 Special Variables ans pi eps flops inf NaN i,j why - default name for results - pi - “help eps” - count floating point ops - Infinity, e.g. 1/0 - Not a number, e.g. 0/0 - root minus one - why not ?

9 LOGO Command

10 The ‘PLOT’ Command (1) >> X = linspace(0, 2*pi, 30); >> Y = sin(X); >> plot(X,Y) >> Z = cos(X); >> plot(X,Y,X,Z);

11 The ‘PLOT’ Command (2) >> W = [Y ; Z] >> plot (X,W) Rotate by 90 degrees >> plot(W,X)


Download ppt "MatlABBA. The Colon Operator (1) This is one MatLab’s most important operators 1:10 means the vector –1 2 3 4 5 6 7 8 9 10 100:-7:50 –100 93 86 79 72."

Similar presentations


Ads by Google