function y=wordmatrix(m)
%this generates a matrix of all words of length m consisting of 0,1,2.
%The words are displayed in the rows in order of their appearance on the
%level m Sierpinski graph given our ordering scheme.
y=[];
for n=1:1:m
    x=[zeros(3^(n-1),1) ; ones(3^(n-1),1) ; 2.*ones(3^(n-1),1)];
    v=[];
    for j=1:1:3^(m-n)
        v=[v ; x];
    end
    y=[v y];
end