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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

random permutation of 3 numbers when repetition of digits are allowed

Asked by salim on 5 Dec 2012

I want to have random permutation of 3 numbers when repetition of digits are allowed.in 3 matrix 1*3 , How can i have them in matrix?Am i supposed to program it or not?

Regards

0 Comments

salim

Products

No products are associated with this question.

2 Answers

Answer by Vinod S on 5 Dec 2012
Accepted answer

Try it this way,

      a=[1 2 3];
      b=[a(ceil(3*rand(1))) a(ceil(3*rand(1))) a(ceil(3*rand(1)))];

Now each entry in b will be a random entry in a, with repetitions allowed

0 Comments

Vinod S
Answer by Matt Fig on 5 Dec 2012
Edited by Matt Fig on 5 Dec 2012

Give this file a try: NPERMUTEK. It solves the general problem so if you need 4 or 5 at a time it will do that too.

npermutek([3 7 8],3)
ans =
       3     3     3
       3     3     7
       3     3     8
       3     7     3
       3     7     7
       3     7     8
       3     8     3
       3     8     7
       3     8     8
       7     3     3
       7     3     7
       7     3     8
       7     7     3
       7     7     7
       7     7     8
       7     8     3
       7     8     7
       7     8     8
       8     3     3
       8     3     7
       8     3     8
       8     7     3
       8     7     7
       8     7     8
       8     8     3
       8     8     7
       8     8     8

0 Comments

Matt Fig

Contact us