asked 85.0k views
1 vote
Create a row vector vA=1:3:34 that has 12 elements. Then, create a new nine-element vector vB from the elements of vA such that the first five elements are the first five elements of the vector vA, and the last four are the last four elements of the vector vA. Use the colon symbol to address a range of elements. (Do not type the elements of the vector vA explicitly.)

asked
User Aldeguer
by
7.9k points

1 Answer

3 votes

Explanation:

Create a row vector vA=1:3:34 that has 12 elements.

Matlab Code:

vA = [1:3:34]

Where vA = [starting element:difference:ending element]

Ouput:

vA = 1 4 7 10 13 16 19 22 25 28 31 34

Create a new nine-element vector vB from the elements of vA such that the first five elements are the first five elements of the vector vA, and the last four are the last four elements of the vector vA

Matlab Code:

% get first five elements from vector vA

vB1 = vA(1:5)

% get last four elements from vector vA

vB2 = vA(9:12)

% combine them together to form row vector vB

vB = [vB1, vB2] (comma or space both are fine)

Ouput:

vB1 = 1 4 7 10 13

vB2 = 25 28 31 34

vB = 1 4 7 10 13 25 28 31 34

answered
User Ashish Agarwal
by
8.1k points
Welcome to Qamnty — a place to ask, share, and grow together. Join our community and get real answers from real people.