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:
Generation of data based on input size

Subject: Generation of data based on input size

From: Lin

Date: 19 Feb, 2009 13:10:03

Message: 1 of 2

Hi all..

for example,

when the input size is 2;
i need to generate
[0 0 1 1;
 0 1 0 1]

when the input size is 3;
i need to generate something like this
[0 0 0 1 1 1 2 2 2 ;
 0 1 2 0 1 2 0 1 2]

when the input size is 4;
i need to generate
[ 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3;
  0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 ]

and this goes on,

Is there a generic code whereby i can prompt user to key the input size and i will be able generate the set of data based on the input? 'dec2bin' is not valid in this context because as the input size goes beyond 2, it will not generate the correct set of data.

The prompting can be realised by using
input('Enter size of iput: ')

What about the generating of data based on the input size? Many thanks for ur help.

Subject: Generation of data based on input size

From: Roger Stafford

Date: 19 Feb, 2009 16:14:01

Message: 2 of 2

"Lin " <shenqlv@yahoo.com> wrote in message <gnjlnb$do4$1@fred.mathworks.com>...
> .....
> when the input size is 2;
> i need to generate
> [0 0 1 1;
> 0 1 0 1]
>
> when the input size is 3;
> i need to generate something like this
> [0 0 0 1 1 1 2 2 2 ;
> 0 1 2 0 1 2 0 1 2]
>
> when the input size is 4;
> i need to generate
> [ 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3;
> 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 ]
> .......

  Let the input size be s.

 [d2,d1] = ndgrid(0:s-1,0:s-1);
 d = [d1(:).';d2(:).'];

Roger Stafford

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