2 Vectors
Open and edit the script q2.m
provided to you to answer the parts of this question.
Note that the script makes a vector named v
for parts (d)–(f) of this question; you must not delete, comment out, or change the vector v
.
(a) [1 mark]
Make a row vector named r1
having values 1, 10, 100, 1000
.
(b) [1 mark]
Using the colon operator, make a row vector named r2
having values 1, 11, 21, 31, 41
.
(c) [1 mark]
Using the linspace
function, make a row vector named r3
having values 0, 10, 20, 30, 40, 50
.
(d) [1 mark]
For parts (d)-(f) the vector v
has a random number of elements and random element values; each time this script is run, the vector v
will change. Your answers should work every time this script is run.
Make a variable third
that has a value equal to the third element of v
.
(e) [1 mark]
Make a variable thirdLast
that has a value equal to the third last element of v
.
(f) [3 marks]
Note that v
always has an even number of elements.
Make a vector w
that is equal to the last half of the elements from v
followed by the first half of the elements from v
; for example, if v
is equal to the vector [1 2 3 4 5 6]
then w
should be equal to the vector [4 5 6 1 2 3]
.