76.2k views
2 votes
Create the following matrix M: 1 7 13 19 25 ?-3 9 15 21 27 5 11 17 2329By writing one command and using the colon to address range of elements (do not type individual elements explicitly), use the matrix M to: (a) Create a five-element row vector named Va that contains the elements of the third row of M. (b) Create a three-element column vector named Va that contains the elements of the fourth column of M. (c) Create an eight-element row vector named Vc that contains the elements of the second row of M followed by the elements of the third column of M.

User Pavitar
by
6.5k points

1 Answer

3 votes

Answer:

Matlab code is:

>>
M=reshape(1:2:29, 3,5)

>>
\% (a)

>>
Va=M(3,:)

>>
\% (b)

>>
Vb=M(:,4)

>>
\% (c)

>>
Vc=[M(2,:) M(:,3)']

Step-by-step explanation:

>>
\% \ Making\ the\ Matrix\ With\ required\ terms\ 1\ to\ 29\ with\ spaces\ of\ 5\ in\ three\ rows

>>
M=reshape(1:2:29, 3,5)


M =

1 7 13 19 25

3 9 15 21 27

5 11 17 23 29

>>
\% (a)

>>
\%\ Slicing\ M\ \ from\ third\ row\ till\ end

>>
Va=M(3,:)


Va =\\\ 5\ 11\ 17\ 23\ 29

>>
\% (b)

>>
\% \ Slicing\ the\4th\ column\ of\ M\ matrix\

>>
Vb=M(:,4)


Vb =\\ 19\\ 21\\ 23\\

>>
\% (c)

>>
\% \ slicing\ the\ 2nd\ row\ and\ 3rd\ column\ of\ M\ Matrix\ and\ combining\ them\ to\ make\ a\ row\ matrix

>>
Vc=[M(2,:) M(:,3)']


Vc =\\ 3\ 9\ 15\ 21\ 27\ 13\ 15\ 17

>>

The code is tested and is correct. If you put a semi colon ' ; ' at the end of every statement then your answer will be calculated but matlab doesn't show it until you ask i.e. typing the variable (Va, Vb, Vc )and press enter.

User Aziz Alto
by
6.8k points