Possible Duplicate:
TikZ: Variable arithmetic result in node name
\documentclass{standalone}
\usepackage{tikz,pgf}
\usetikzlibrary{decorations.markings,%
snakes,fit,scopes,arrows,calc,shapes.misc,%
shapes.arrows,chains,matrix,positioning,decorations.pathmorphing,shapes,backgrounds,%
decorations.text}
\begin{document}
\newcommand{\bbrect}[3]{
\pgfmathsetmacro\result{#1+1};
\node[rectangle,draw,fit=(A-#1-\result.north west) (A-#1-#2.south east), inner sep = 0pt] (block#3) {}
}
\begin{tikzpicture}
\ttfamily
\begin{scope}
\matrix (A) [matrix of nodes, ampersand replacement = \&] {
{0} \& {0} \& {1} \& {0} \& {1} \& {0}\\
{0} \& {0} \& {0} \& {1} \& {1} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {1} \& {0}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {1}\\
{0} \& {0} \& {0} \& {0} \& {0} \& {0}\\
};
\end{scope}
\bbrect{1}{5}{1};
\end{tikzpicture}
\end{document}
Inside the newcommand the entry A[i,i+1] is accessed, but this gives "illegal unit of measure" error.
\pgfmathtruncatemacroinstead of\pgfmathsetmacro. (Disclaimer: this might only work with PGF2.10, I don't remember when the\pgfmathtruncatemacromacro was introduced.) – Andrew Stacey Jan 09 '12 at 08:06