Write a M-file script that creates a row vector that has 100 elements with dimen
ID: 3883776 • Letter: W
Question
Write a M-file script that creates a row vector that has 100 elements with dimensions of (1 times 100) and name the vector a. The first 25 elements have of value 1, the next 25 elements have value of zero, the next 25 elements have value of 2, the next 25 elements have value of -1. Concatenate the four sub arrays into an array named a. Include the size function to determine the dimensions of the array progmanatically. Assign the variable vector_size to the size function as the output. Next using indexing include code to assign the variable a89 to equal the value of the 89th element of a. You must include comments describing your code! Your Script % create four sub vectors and then concatenate % them into a single row vector named % b1 is the first sub array % you must create the remaining three sub arrays b1 = ones (1, 25): % b2 = % b3 = % b4 = % You must assign variable a to the concatented array a = [b1 b2 b3 b4]: % your must assign the variable vector_size to a built in function to % progamattically determine the dimension of vector a vector_size =size(a) % You must assign the variable name a89 to an expression indexing the 89 element of a a89 = a(1, 89)Explanation / Answer
%Create four vectors namely b1,b2,b3,b4
%Vector b1 is the first one and it contains 25 one's
b1 = ones(1,25);
%Vector b2 is the second one and it contains 25 zeroes
b2 = zeros(1,25);
%Vector b3 is the third one and it contains 25 two's
b3 = ones(1,25)*2;
%Vector b4 is the fourth one and it contains 25 -1's
b4 = ones(1,25)*-1;
%Now we need to concatenate all vectors/subarrays into
% a concatenated array named a
a = [ b1 b2 b3 b4];
% Assign the variable vector_size to a built in function called size() to
%programatically determine the dimensions of a vector a
vector_size = size(a)
% Assign the variable named a89 to an expression indexing the 89 element of a
a89 = a(1,89)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.