Matlab Code, Tracking Table - Computer Methods in Biomedical Engineering | BME 201, Exams of Biology

Material Type: Exam; Professor: Sawicki; Class: Computer Methods in Biomedical Engineering; Subject: Biomedical Engineering; University: North Carolina State University; Term: Spring 2011;

Typology: Exams

2010/2011

Uploaded on 03/31/2011

goalie4eva
goalie4eva 🇺🇸

31 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
PRACTICE EXAM I - BME 201 - SPRING 2011
Note: Please bring a calculator to the exam. You will need it and I will not have
extras.
Question 1 (40 pts):
A = [1,6,8; 3,5,1; 4,7,2];
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;
pf2

Partial preview of the text

Download Matlab Code, Tracking Table - Computer Methods in Biomedical Engineering | BME 201 and more Exams Biology in PDF only on Docsity!

PRACTICE EXAM I - BME 201 - SPRING 2011

Note: Please bring a calculator to the exam. You will need it and I will not have extras.

Question 1 (40 pts):

A = [1,6,8; 3,5,1; 4,7,2];

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?

*OTHER PRACTICE QUESTIONS:

  1. For the following code, what are the final values of a and banana.

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;

  1. Write the code to produce an array of the indices for the values in the array x that are exactly zero. Your code should work for any one dimensional array, not just for the given x.

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.