Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a script file to solve this problem Vector manipulation is an integrat part of MATLAB. Do the following exercises using the vector shown below

image text in transcribed
image text in transcribed
image text in transcribed
Write a script file to solve this problem Vector manipulation is an integrat part of MATLAB. Do the following exercises using the vector shown below to practice your sikils. Notes: Do not hated code any of the answers for this problem. You cannot use iteration for any of the parts of this problem. For example, vec=[452847.264257.2557.432.573365233430.65343]; However, the input can be a vector of any length of any value. To prevent you from hard coding the result, we will use random generated vector for testang. Read MATLAB Marina: 10 Amays and Vectors, hitpillwww mathabmarina comydannays htmlagain if you have no idea how to do them - Create a new vector, vecr, that is the reverse of vec, (Hint. negative increment). - Create a new vector, vec2. that contains every other element of vec starting with the second element: - Create a new vector, vec3R, that contains every third element of vec starting from the fast element and going toward the first element in vec. fHint negative increment) - Create a new vectot, vecB, that swaps the first and second hasves of vec, so vecb will contain the second hait of vec tollowed oy the first haif of vec, (Hint gef the firs hall and the second nat and then creale the new one) Hint for the foliowngg. you need to use the logical operators and or find memod - Create a niew vector vecs, thiat contains all of the elements in the vec that are smarif than is. The numbers should be in the same order is they were in - Create a new vector, vect that contains true wherever vec is greater than 10 and fase everywhere else - Creale a new vector feof that contains the ingices of every element in vec that is equal no.2 - Create a new vector, vech that is the satie as the vector vec except that all of the 2 f have pech deteledl 1 Dinitialize the vector - input 2 \% Here for MATLAB grader, we will use a randon generated vector for testing. 3N - randi ([10 38]) \% Random length for a vector between 18 to 50 4 vec - randi ([018],1,N)z randon vector of length N of the range to 10. 5 Xvec = [45.2.847.64257.4574325.7336523343865343] : 6 XHint: you can use the above hard coded exnple input vector to check your inplenentation on your om latlab installation ty unce 7 But when you try to pass the MrLas Grader, connent out line 5 Tcreate a new vector, vech, that is the reverse of vec. (Hint: negative Increnent) 10 vecRe 11 12 TCreate a new vector, vecz. that contains every other elenent of vec starting with the second oleent. 13) vec2. 14 1s Toreate a new vector, vec3R, that contains eveny thind elenent of yec starting fron the last elenent and golng tovard the flrit 16 vecaR= 17 17. *Create a neis vector, vecE, that swaps the first and second halyes of Hec, so vece wt11 contaln the seconi half of vec foltowed 19. halfposintindexo 120 vecfirsthalf= 24 vecsecondialf = 2. vecb - 24 XHint: for the following, you need to use the logical operators and/or find method \%create a new vector, vecs, that contains all of the elenents in the vec that are sailer than ws. The nuabers thoold be in the sae booleanvecLess Than 45 - vecs = XCreate a new vector, vect, that contains true wherever vec is greater than 10 and false everyahiern else vecT" Xcreate a new vector, vecf, that contains the Indices of every elenent in vec that is equal to 2. vecf- Rcreate a new vector, vecA, that is the sase as the vector vec except that all of the 2s have bein selirtes. vecA=

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions