Using Matlab: EE 221 Computing for Engineers Homework #12 1 Write a function tha
ID: 3349245 • Letter: U
Question
Using Matlab:
EE 221 Computing for Engineers Homework #12 1 Write a function that is called Get_Min1, which will take a Vector V as input and return a scalar value V as output. The function will do the following Will get the length of the vector V Initialize the minimum value Z to the first element in V Initialize the index value i =0; Will scan each element in the vector V using a while loop Once all the elements in V are scanned, exist the while loop a. b. d. e. Submit your Get_Min1.m file via blackboard 2- Create a script and save it as HW12.m. The script will do the following a. Create a random column vector X of size (100x1) b. Save the vector X as .MAT file called 'My data1.mat' using the command save c. Clear the workspace using the command clear. Note that the workspace is empty d. Load the vector X using the command load e. Call the function Get Min1() function on the vector X and assign it to m1. The command looks like m1-Get Min1(X) Compare the value of m1 to the result of the building function min(). The command looks like m2-min(X). You should get the same value Run the script several times to create different random vectors. You still will get the same min values (m1 = m2) f. g.Explanation / Answer
Matlab Script for question 1:
function Z = Get_Min1(V)
V_len = length(V);%finding length
Z = V(1);%initializing with first element
i = 0;%initializing index value with 0
while i<V_len %scanning all the elements
if V(i+1)<Z %checking if current element from V is less than Z if so we replace Z with current element of V
Z = V(i+1);
end
i = i+1;
end
end
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.