Trace through each of the following loops by hand, stating what the
output is. Answers to traces and the three small programs due February
19. You may do this one in assigned groups of 2. Make sure you put both
your names on what you send. Only submit one per group.
1) prods=1
for jj=[1:6]
fprintf('%d ',jj*jj-1)
prods=prods*(jj+1);
fprintf('xx')
end
prods
2) A='hellohowareyou?'
for kk=[1:2:length(A)]
A(kk)
end
2.5) B=[1 3 8 2 7 22 11 66]
for jj= [1:length(B)]
if mod(B(jj),2) == 0
B(jj)=B(jj)+1
else
B(jj)=B(jj)-1
end
end
3)for ii=[1:6]
for jj = [1:7]
fprintf('*')
end
for kk = [1:ii]
fprintf('8')
end
fprintf('\n')
end
4)for ii =[1:7]
for jj = [1:8]
fprintf(' '%d' ',ii*jj)
end
fprintf('\n')
end
5) for ii = [1:9]
for jj=[1:ii]
if (mod(jj,3)==0)
fprintf('e')
elseif (mod(jj,5 == 0)
fprintf('z')
else
fprintf('o')
end
end
fprintf('\n')
end
6) for ii=[1:4]
for jj=[1:3]
A(ii,jj)=ii+jj
end
end
A
7)DNA = 'aaaggattaaaacccaaattt'
v=length(DNA);
for ii = [1:v]
DNA2(ii) = DNA(v-ii+1)
end
DNA2
DNA2 == DNA
8)
DNA = 'aaaggattaaaacccaaattt'
count =0;
v=length(DNA);
ii=1;
while (ii<=v-2)
if (DNA([ii:ii+2])== 'aaa')
count=count+1;
ii=ii+3;
else
ii=ii+1;
end
end
count
9-11 ) write code to
Find the first location of a t in a string of DNA
Find the number of a certain string in a string of DNA, such as the
number of 'tgaa'
Find the first location of a certain string in a string of DNA