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:
Create a special matrix!

Subject: Create a special matrix!

From: Erik Andersson

Date: 5 May, 2010 12:19:06

Message: 1 of 4

Hello!
I've would like to create a matrix 1000*3 i dimension which has all the combinations of the numbers 1 to 10 in it, i.e

1 1 1
1 1 2
. . .
1 1 10
1 2 1
1 2 2
. . .
1 2 10
1 3 1
And so on...

Someone?

Subject: Create a special matrix!

From: Sean

Date: 5 May, 2010 13:26:04

Message: 2 of 4

"Erik Andersson" <annerk02@student.umu.se> wrote in message <hrrnnq$mpa$1@fred.mathworks.com>...
> Hello!
> I've would like to create a matrix 1000*3 i dimension which has all the combinations of the numbers 1 to 10 in it, i.e
>
> 1 1 1
> 1 1 2
> . . .
> 1 1 10
> 1 2 1
> 1 2 2
> . . .
> 1 2 10
> 1 3 1
> And so on...
>
> Someone?

One way:
>>special_matrix = [ones(1000,1),sort(repmat([1:10]',100,1)) ,repmat([1:10]',100,1)];

Subject: Create a special matrix!

From: Sean

Date: 5 May, 2010 13:32:05

Message: 3 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hrrrlc$cjo$1@fred.mathworks.com>...
> "Erik Andersson" <annerk02@student.umu.se> wrote in message <hrrnnq$mpa$1@fred.mathworks.com>...
> > Hello!
> > I've would like to create a matrix 1000*3 i dimension which has all the combinations of the numbers 1 to 10 in it, i.e
> >
> > 1 1 1
> > 1 1 2
> > . . .
> > 1 1 10
> > 1 2 1
> > 1 2 2
> > . . .
> > 1 2 10
> > 1 3 1
> > And so on...
> >
> > Someone?
>
> One way:
> >>special_matrix = [ones(1000,1),sort(repmat([1:10]',100,1)) ,repmat([1:10]',100,1)];

That was wrong :(

I meant this:
special_matrix = [sort(repmat([1:10]',100,1)), repmat(sort(repmat([1:10]',10,1)),10,1) ,repmat([1:10]',100,1)];

Subject: Create a special matrix!

From: Matt J

Date: 5 May, 2010 15:45:22

Message: 4 of 4

"Erik Andersson" <annerk02@student.umu.se> wrote in message <hrrnnq$mpa$1@fred.mathworks.com>...
> Hello!
> I've would like to create a matrix 1000*3 i dimension which has all the combinations of the numbers 1 to 10 in it, i.e
======================


[c3,c2,c1]=ndgrid(1:10,1:10,1:10);
special_matrix=[c1(:),c2(:),c3(:)];

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