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:
matrix formation

Subject: matrix formation

From: ratnesh kumar

Date: 28 Oct, 2010 14:43:03

Message: 1 of 2

hi, without the use of permutation. here i want to make a M matrix which contains 'n' numbers.
in this example number exits are(1,2,3,4,5).
M=1 1 1
     1 1 2
     1 1 3
     1 1 4
     1 1 5
     1 2 2
     1 2 3
     1 2 4
     1 2 5
     1 3 3
     1 3 4
     1 4 4
     2 2 2
     2 2 3
     2 2 4
     2 3 3
     2 3 4
     3 3 3
help me please ....... thanks

Subject: matrix formation

From: Roger Stafford

Date: 28 Oct, 2010 15:46:04

Message: 2 of 2

"ratnesh kumar" <iam_ratnesh@yahoo.co.in> wrote in message <iac25n$d8j$1@fred.mathworks.com>...
> hi, without the use of permutation. here i want to make a M matrix which contains 'n' numbers.
> in this example number exits are(1,2,3,4,5).
> M=1 1 1
> 1 1 2
> 1 1 3
> 1 1 4
> 1 1 5
> 1 2 2
> 1 2 3
> 1 2 4
> 1 2 5
> 1 3 3
> 1 3 4
> 1 4 4
> 2 2 2
> 2 2 3
> 2 2 4
> 2 3 3
> 2 3 4
> 3 3 3
> help me please ....... thanks
- - - - - - - - - - - -
  The way your pattern starts out, I would have expected 35 rows instead of your 18. For example, after the [1 4 4] I would expect [1 4 5] and then [1 5 5]. Just what is the logic of your sequence?

  Just assuming you meant the full 35, then for m chosen out of n numbers, you would get (m+n-1)!/m!/(n-1)! altogether, and you can get the sequences from 'nchoosek':

 s = nchoosek(1:n+m-1,m);
 s = bsxfun(@minus,s,0:m-1);

Roger Stafford

Tags for 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