Extra Problem #1:
By hand, determine all variable iterations of the nested for loop below:
loop = [-4 7 5];
initial = 2:2:20;
value = 10:-1:1;
k = 1;
build = ones(3,6);
for m = 1:length(loop)
for n = 3:-1:1
stamp(n) = loop(n) + initial(m) -value(m+n)
end
build(:,k) = stamp'
k = k + 2
end
all variable iterations of the nested for loop are stamp, build and k Trace: ----------- stamp = 0 0 0 stamp = 0 1 0 stamp = -11 1 0 build = -11 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 k = 3 stamp = -11 1 3 stamp = -11 4 3 stamp = -8 4 3 build = -11 1 -8 1 1 1 1 1 4 1 1 1 0 1 3 1 1 1 k = 5 stamp = -8 4 6 stamp = -8 7 6 stamp = -5 7 6 build = -11 1 -8 1 -5 1 1 1 4 1 7 1 0 1 3 1 6 1 k = 7
Get Answers For Free
Most questions answered within 1 hours.