"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <ibdbkn$8gd$1@fred.mathworks.com>...
> "Mahesh Ramaraj" <mramaraj@purdue.edu> wrote in message <ibcojb$suv$1@fred.mathworks.com>...
> > Hi, I have some difficulty if forming the following matrix.
> > n = 3; (number of columns)
> > m = (n1)*n; (number of rows)
> > when n =3, i need the following matrix:
> > A = [1 1 0
> > 1 0 1;
> > 1 1 0;
> > 0 1 1;
> > 1 0 1;
> > 0 1 1]
> >
> > and when n = 4,
> > A = [1 1 0 0;
> > 1 0 1 0;
> > 1 0 0 1;
> > 1 1 0 0;
> > 0 1 1 0;
> > 0 1 0 1;
> > 1 0 1 0;
> > 0 1 1 0;
> > 0 0 1 1;
> > 1 0 0 1;
> > 0 1 0 1;
> > 0 0 1 1]
> >
> > And when n increases, the matrix expands accordingly.
> > As you can there is a pattern for 1's, they appear consequently for n1 rows and shifts by one column and the ones have change according to each row. It would be great if someone could help with this. I have spent quite a bit of time on this. Thanks for the help.
>           
> Assuming it is this specific pattern with 1's, 1's, and 0's with n columns, do this:
>
> A = [repmat(1,n1,n1);repmat(eye(n1),n,1)];
> A = reshape([A(:);repmat(1,n1,1)],[],n);
>
> Roger Stafford
Thanks Roger, that helped a lot.
