ABCs_iteration

# ABCs_iteration - B = 0 for index = x B = B index/length(x...

This preview shows page 1. Sign up to view the full content.

Sheet1 Page 1 function [A A_method B B_method C] = ABCs_iteration(x) % PROBLEM 5. The ABCs of Iteration % % This is a multi-part problem. Do each of the parts below. % % DO NOT CHANGE THE FUNCTION HEADER (the first line of code) % 1) for loops. Below are two for loops that each find the mean of all the % values in x. Each for loop uses a different style, either % 'direct-access' or 'indexing'. Replace the comments %fill me in% in each % of the for loops without changing any of the other lines so that A and B % will be equal to the mean of x. % % first for loop A = 0 for index = 1:length(x) A = A + x(index)/length(x) end % % second for loop
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: B = 0 for index = x B = B + index/length(x) end % 2) What method is used above to find A and B? Store your answer as a % string in the variables named A_method and B_method. Each variable % should be exactly equal to either 'direct-access' or 'indexing'. A_method = 'indexing' B_method = 'direct-access' % 3) while loops. The while loop below is supposed to store the mean of all % the elements in x in the variable C. Replace the comments %fill me in% % so that the below while loop will work correctly. C = 0 count = 1 while count <= length(x) C = C + x(count)/length(x) count = count + 1 end...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online