for i = 1:10

   % put a 1 on the main diagonal
   A(i,i) = 1;

   % put a 2 before the diagonal, but only in the last
   % nine rows (the first row doesn't have an entry
   % right before the diagonal.)
   if (i > 1)
      A(i,i-1) = 2;
   end

   % put a 2 after the diagonal, but only in the first
   % nine rows.  (The last row doesn't have an entry
   % right after the diagonal.)
   if (i < 10)
      A(i,i+1) = 2;
   end

end

% print the result
A