The test suite workspace has two variables A and B described as follows: The var
ID: 3808002 • Letter: T
Question
The test suite workspace has two variables A and B described as follows: The variable A is a 6-element row vector of random integers between 0 and 20. The variable B is a 10 element column vector of random integers between 0 and 50. Write a script that uses A and B to generate the vectors below and assign to the indicated variable names. Generate a vector named ABrow that is a 16-element row vector consisting of the elements of A followed by the dements of B. Generate a second vector named BAcol that is a 16-element column vector consisting of the elements of ABrow in reverse order. Generate a third vector named First Half A_Last Half B that is an 8 element row vector consisting of the first 3 elements of A followed by the last 5 elements of B.Explanation / Answer
Here is the code for you:
% The variable A is a 6-element row vector of random integers between
% 0 and 20.
A = randi(21, 1, 6) - 1;
% The variable B is a 10-element column vector of random integers between
% 0 and 50.
B = randi(51, 10, 1) - 1;
% Generate a vector named ABrow that is a 16-element row vector
% consisting of the elements of A followed by the elements of B.
ABrow = [A transpose(B)];
% Generate a second vector named BAcol that is a 16-element column vector
% consisting of the elements of ABrow in reverse order.
BAcol = fliplr(ABrow);
% Generate a third vector named FirstHalfA_LastHalfB that is an 8-element
% row vector consisting of first 3 elements of A followed by the last 5
% elements of B.
X = transpose(B);
firstHalfA_LastHalfB = [A(1 : 3) X(6 : 10)];
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.