Using Matlab please answer problem 1, parts a and b. Please explain each for part a. Please explain the result for part b.
1. MATLAB ARRAY INDEXING
(a) Explain what the each of the following will produce:
jk1 = 2:4:17
jk1 = 99:-1:88
ttt = 2:(1/9):4
(b) Extract or insert numbers in a vector. Try the following:
xx= [ ones(1,4), [2:2:11], zeros(1,3) ]
xx(3:7)
length(xx)
Explain the result.
jk1 = 2:4:17 creates a vector starting from 2 ending with 17 with step size 4
2 6 10 14
jk1 = 99:-1:88 creates a vector staring from 99 upto 88 by decrementing 1 each time
99 98 97 96 95 94 93 92 91 90 89 88
ttt = 2:(1/9):4 creates a vector from 2 to 4 with step size 1/9 ttt = Columns 1 through 8: 2.0000 2.1111 2.2222 2.3333 2.4444 2.5556 2.6667 2.7778 Columns 9 through 16: 2.8889 3.0000 3.1111 3.2222 3.3333 3.4444 3.5556 3.6667 Columns 17 through 19: 3.7778 3.8889 4.0000
b)
ones(1,4) gives 1 row 4 columns 1s -> 1 1 1 1
[2 2 11] gives 2 4 6 8 10
zeros(1,3) zeros of 1 row and 3 columns -> 0 0 0
appending all these gives xx = [1 1 1 1 2 4 6 8 10 0 0 0]
xx(3:7) gives a vector of elements xx starting from 3 to 7 --> 1 1 2 4 6
length(xx) gives length of xx that is 12
Get Answers For Free
Most questions answered within 1 hours.