Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
auto generate ones and zeros in matrix

Subject: auto generate ones and zeros in matrix

From: Darren LEE

Date: 22 Oct, 2010 02:48:55

Message: 1 of 8

Hi everyone,

Is there any matlab code can allow me to do auto generate ones and
zeros in matrix format? I want to produce like these:

z = [1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
       0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0;
       0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0;
       0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1]


Please help to give me some guide. Thanks in advance.

Subject: auto generate ones and zeros in matrix

From: Nasser M. Abbasi

Date: 22 Oct, 2010 03:33:20

Message: 2 of 8

On 10/21/2010 7:48 PM, Darren LEE wrote:
> Hi everyone,
>
> Is there any matlab code can allow me to do auto generate ones and
> zeros in matrix format? I want to produce like these:
>
> z = [1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
> 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0;
> 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0;
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1]
>
>
> Please help to give me some guide. Thanks in advance.

try:

N = 5;
a = [ones(1,N) zeros(1,N); zeros(1,N) ones(1,N)];
sub = zeros(size(a));
super = sub;

full(blktridiag(a,sub,super,2))


--Nasser

Subject: auto generate ones and zeros in matrix

From: Darren LEE

Date: 22 Oct, 2010 03:52:10

Message: 3 of 8

On Oct 22, 11:33 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
> On 10/21/2010 7:48 PM, Darren LEE wrote:
>
> > Hi everyone,
>
> > Is there any matlab code can allow me to do auto generate ones and
> > zeros in matrix format? I want to produce like these:
>
> > z = [1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
> >         0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0;
> >         0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0;
> >         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1]
>
> > Please help to give me some guide. Thanks in advance.
>
> try:
>
> N     = 5;
> a     = [ones(1,N) zeros(1,N); zeros(1,N) ones(1,N)];
> sub   = zeros(size(a));
> super = sub;
>
> full(blktridiag(a,sub,super,2))
>
> --Nasser

Hi Nasser,

Thanks for your reply. But I am having this error, after running the
code:

??? Undefined function or method 'blktridiag' for input arguments of
type 'double'.

Subject: auto generate ones and zeros in matrix

From: John

Date: 22 Oct, 2010 04:00:07

Message: 4 of 8

Darren LEE <darren.leesh@gmail.com> wrote in message <872fb2c9-3d38-470b-bdf7-e69b6d001f64@r31g2000prg.googlegroups.com>...
> On Oct 22, 11:33 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
> > On 10/21/2010 7:48 PM, Darren LEE wrote:
> >
> > > Hi everyone,
> >
> > > Is there any matlab code can allow me to do auto generate ones and
> > > zeros in matrix format? I want to produce like these:
> >
> > > z = [1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
> > >         0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0;
> > >         0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0;
> > >         0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1]
> >
> > > Please help to give me some guide. Thanks in advance.
> >
> > try:
> >
> > N     = 5;
> > a     = [ones(1,N) zeros(1,N); zeros(1,N) ones(1,N)];
> > sub   = zeros(size(a));
> > super = sub;
> >
> > full(blktridiag(a,sub,super,2))
> >
> > --Nasser
>
> Hi Nasser,
>
> Thanks for your reply. But I am having this error, after running the
> code:
>
> ??? Undefined function or method 'blktridiag' for input arguments of
> type 'double'.
>


http://www.mathworks.com/matlabcentral/fileexchange/10603-block-tri-diagonal-matrices

Subject: auto generate ones and zeros in matrix

From: Nasser M. Abbasi

Date: 22 Oct, 2010 04:04:02

Message: 5 of 8


>

> Thanks for your reply. But I am having this error, after running the
> code:
>
> ??? Undefined function or method 'blktridiag' for input arguments of
> type 'double'.
>

oh, I thought you'll just google it ;)

It is a fucntion at the Matlab file exchange.

Author: John D'Errico

hth

--Nasser

Subject: auto generate ones and zeros in matrix

From: Darren LEE

Date: 22 Oct, 2010 04:28:59

Message: 6 of 8

On Oct 22, 12:04 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:
> > Thanks for your reply. But I am having this error, after running the
> > code:
>
> > ??? Undefined function or method 'blktridiag' for input arguments of
> > type 'double'.
>
> oh, I thought you'll just google it ;)
>
> It is a fucntion at the Matlab file exchange.
>
> Author: John D'Errico
>
> hth
>
> --Nasser

Thanks John and Nasser. U guys are really great.

Subject: auto generate ones and zeros in matrix

From: Roger Stafford

Date: 22 Oct, 2010 06:09:04

Message: 7 of 8

Darren LEE <darren.leesh@gmail.com> wrote in message <f9c8a9c1-994b-4087-9555-ca844408d052@29g2000prb.googlegroups.com>...
> Hi everyone,
>
> Is there any matlab code can allow me to do auto generate ones and
> zeros in matrix format? I want to produce like these:
>
> z = [1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;
> 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0;
> 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0;
> 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1]
>
>
> Please help to give me some guide. Thanks in advance.
- - - - - - - -
  You could also do it this way.

m = 5; n = 4;
z = reshape(repmat(reshape(eye(n),1,[]),m,1),[],n).';

Roger Stafford

Subject: auto generate ones and zeros in matrix

From: Bruno Luong

Date: 22 Oct, 2010 06:30:14

Message: 8 of 8

kron(eye(4),ones(1,5))

% Bruno

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us