

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Professor: Sawicki; Class: Computer Methods in Biomedical Engineering; Subject: Biomedical Engineering; University: North Carolina State University; Term: Spring 2011;
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Note: Please bring a calculator to the exam. You will need it and I will not have extras.
Question 1 (40 pts):
a. Write Matlab code to extract the third column of the matrix A and set it equal to a variable called third_column. (8 pts.) b. Write Matlab code to extract values from A to create a column vector called diag_vec that is comprised of the elements along the diagonal spanning from top left to bottom right of A. (8 pts.) c. What will the Matlab command ewise = A (:,1).* A (:,3) set ewise equal to? (8 pts.) d. What will the Matlab command not_ewise = A (1, :)* A(:,3) set not_ewise equal to? (8 pts.) e. Write Matlab code to extract the last two elements of the third row of A and store them in a row vector called row_vec (8 pts.)
Question 2 (30 pts):
imagedata = [8,20,6,11,3];
a. Write Matlab code using a for loop to return the number of elements in the array imagedata that are between the values 5 and 18. The code should be general enough to handle data arrays of different lengths (15 pts). b. Track the values in your code to verify that it returns the correct answer (15 pts).
Question 3 (30 pts.):
updown = [2, 4, 6, 8, 7, 5, 4]; time = [1, 2, 3, 4, 5, 6, 7];
a. Write Matlab code using a while loop to determine the time when the value of the array updown first stops increasing (15 pts). b. Track the values in your code to verify it returns the correct answer (15 pts).
BONUS (20 pts.): For the following code:
x=[2,4,7,9]; y=3; z=[4 5 2 6 ; 3 7 2 4 ; 5 9 8 4 ; 1 1 6 3 ] ;
N=length(z(:,1));
for k=1:length(x) ; for n=1:N ww = z(n,k)*y + x(k) W(k,n) = ww;
end k n ww end
a. Create a tracking table fill in the rows with the current values of k, n and w on each pass through the code until it finishes executing.
b. What is the final value of W?
c = [6 12 30]; d = [4 5 6]; a = 6;
apple = c.*2; grape = apple./a; apple = grape + d; banana= d + a;
if a> a=apple; end
grape = c + a; c=0;
for k=1: length(d) d(k) = banana(k)+ k; end
banana=d;
x= [− 1 0.3 0 2 1.2 0 0 4 −0.5 0.7 0 − 2 6 0];
a. Use a for loop. b. Use a while loop.