11 Concatenate vectors
In MATLAB, a programmer can join two (or more) arrays to form a new single array using an operation called concatenation.
Given two row vectors u
and v
the programmer can create a new row vector w
containing all of the elements of u
followed by all of the elements of v
by writing:
w = [u v];
Given two column vectors u
and v
the programmer can create a new column vector w
containing all of the elements of u
followed by all of the elements of v
by writing:
w = [u; v];
Create a new script and save it as q6.m
. To the newly created script, add some MATLAB statements that perform the following steps in order:
- Creates a \(1 \times 10\) vector of all zeros named
u
. Use the functionzeros
to create the vector. - Creates a \(1 \times 10\) vector of all ones named
v
. Use the functionones
to create the vector. - Creates a row vector
w
formed by concatenatingu
withv
- Creates a \(8 \times 1\) vector of all ones named
a
. Use the functionones
to create the vector. - Creates a \(8 \times 1\) vector of all zeros named
b
. Use the functionzeros
to create the vector. - Creates a column vector
c
formed by concatenatinga
withb