Effacer les filtres
Effacer les filtres

how to generate all possible combination from a sequence

5 vues (au cours des 30 derniers jours)
Elysi Cochin
Elysi Cochin le 28 Mai 2016
Modifié(e) : Stephen23 le 30 Mai 2016
how to generate all possible combination from a n-dimensional vector without repetition of numbers.. i wanted combination of vec = 1:11;
eg:
vec = [1 2 3]
result = [
1 2 3;
1 3 2;
2 3 1;
2 1 3;
3 2 1;
3 1 2];
  1 commentaire
Stephen23
Stephen23 le 28 Mai 2016
Modifié(e) : Stephen23 le 28 Mai 2016
Your question is erroneous: these are not the combinations of vec, but are actually the permutations.
The difference is very simple:
  • if the order does not matter: combinations.
  • if the order is important: permutations.
You should make a complaint to your high school that they did not teach these basic mathematical terms correctly. Ask for your money back!

Connectez-vous pour commenter.

Réponse acceptée

Stephen23
Stephen23 le 28 Mai 2016
>> perms(1:3)
ans =
3 2 1
3 1 2
2 3 1
2 1 3
1 2 3
1 3 2
  5 commentaires
Elysi Cochin
Elysi Cochin le 30 Mai 2016
i tried A=perms(uint8(1:11)) still Out of memory
Stephen23
Stephen23 le 30 Mai 2016
Modifié(e) : Stephen23 le 30 Mai 2016
@Elysi Cochin: essentially you have two choices:
  1. buy more memory for your computer.
  2. change your algorithm.
As the other commenters have already told you, even though beginners often imagine that their computer has never-ending memory and processing capabilities, in practice it is very simple to define a few commands that far exceed any computer's abilities.
Your task (as the author of your algorithm) is to understand this and to get information on alternatives. One possibility is to use a permutation generator that generates each permutation at a time (not all at once). This will be slow, but it will avoid the memory problems. You will find several submissions on FEX that provide this functionality:
Ultimately however, you will just find that this takes too long, and you will then have to consider alternatives to your algorithm. Good luck!

Connectez-vous pour commenter.

Plus de réponses (1)

Jos (10584)
Jos (10584) le 30 Mai 2016

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by