How to generate permutations? by increase or decrease no. of unique values??

1 visualización (últimos 30 días)
a = [30 30 30 0 0 10 10 10 20 20];
unique(a)
ans =
0 10 20 30
I want to generate some permutations which numel(a) should be 10. unique(a) should be same. but every unique value should be greater than or equal to 2. please help me for generate permutations by "increase or decrease" number of unique values(elements). perms(a) gives multiple results and same elements. I need only 100 permutations.
[30 30 20 0 0 10 10 10 20 20];% number of theta changed
[30 30 20 0 0 10 0 10 20 20];
[30 30 30 0 0 10 20 10 20 20];

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Feb. de 2016
If unique(a) should be the same then unique(a) would need to include 0, which would contradict your "every unique value should be greater than or equal to 2".
I do not understand what you are trying to do.
If you need unique permutations, then why not
p = unique(perms(a), 'rows');
This will generate 25200 rows. You could then select 100 rows randomly from the result, such as
rp = p(randperm(size(p,1), 100),:);
  2 comentarios
Triveni
Triveni el 20 de Feb. de 2016
Sir, Actually i want to change the number of unique element means sometime 3 no of 30 next may be 4. number of theta should change.
Walter Roberson
Walter Roberson el 20 de Feb. de 2016
Please indicate which parts of the following are correct:
  • The vector to generate the permutations from should have 10 elements
  • You start with a vector "a". You take the unique elements of that, throw away 0 if it is there, and whatever is left over should form part of the vector whose permutations are to be taken. Call these unique non-zero members of "a" under the name "U" for the discussion below.
  • You have a target for number of unique elements for this run, which you have set in a variable
  • The target number of unique elements for the vector to be permuted should be chosen randomly from between 3 and 10.
  • If the target number of unique elements is smaller than the number of elements in U, then a random subset of U should be chosen
  • If the target number of unique elements is larger than the number of elements in U, then additional elements need to be generated
  • Values to be generated shall have a minimum value of 2, and a maximum value of 30
  • Values to be generated shall be consecutive integers starting from 2
  • Values to be generated shall be taken as uniformly distributed random integers in the range noted above
  • Values to be generated shall be taken as uniformly distributed random floating-point values in the range noted above
  • Once the unique values have been generated, a random number of each of them shall be used such that a total of 10 elements are generated
  • Random elements are to be generated to fill only the locations in "a" that were 0
  • locations in "a" that are 0 may only be filled with new values, not values that occur already in "a"
  • locations in "a" that are 0 may be filled with any of the values, including ones that already occur in "a", provided that the overall result has the necessary number of unique values
  • The order of the vector of values to generate the permutations from does not matter
  • The order of the vector of values to generate the permutations from does matter
  • A woodchuck would chuck as much wood as a woodchuck could chuck, if a woodchuck could chuck wood
  • The first 100 permutations generated by perms() are to be used, no matter what they come out as
  • The first 100 unique permutations generated by perms() are to be used
  • All unique permutations are to be chosen from randomly, selecting 100 unique permutations

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by