% step 1: create zero-matrix of size 8x8
m = zeros(8);
% step 2: iterate over matrix in a nested for loop, consider only odd rows
% scalar to keep track of values in matrix
s = 0;
% all odd rows, in which values increase left to right
for i=1:2:8
for j=1:8
m(i,j) = s;
s = s + 1;
end
s = s + 8;
end
% step 3: display intermediate results
m
% step 4: iterate over matrix again, this time even rows
% reset s to smallest value in second row; this one starts on the right
% side of the matrix
s = 8;
% all even rows, in which values increase right to left
for i=2:2:8
for j=8:-1:1
m(i,j) = s;
s = s + 1;
end
s = s + 8;
end
m
image(m), colormap(jet(64));