Adding all possible combinations of array elements
Mostrar comentarios más antiguos
I have an array of elements,
How would I generate a new array of all possible combinations, multiples, and combinations of multiples within a threshold limit of, say, 30?
ex:
X=[a b c d]; where a, b, c, d are real, positive, small integers
M=[a, b, c, d, 2*a, 2*b, ... 3*a, 3*b,...4*a, 4*b, ...a+b, a+b+c,... 2a+2b,...2a+c,... 10a+10b+d, ... .. .. ]
M(M>=30)=[];
where ALL possible combinations are there, excluding repeat combinations, but including repeat numbers
3 comentarios
Image Analyst
el 12 de Ag. de 2014
Editada: Image Analyst
el 12 de Ag. de 2014
Well I think that would be an infinite number of numbers, unless you put on some constraints, like the multiplication factors must be positive integers or something.
Is this homework? It kind of sounds like homework.
And do you need to keep track of the multiplication factors that were used to create each number?
Image Analyst
el 12 de Ag. de 2014
Hey, are you still there?
K
el 12 de Ag. de 2014
Respuestas (1)
Ahmet Cecen
el 12 de Ag. de 2014
0 votos
Use combnk to get the the unique combinations over a,b,c and d. For each of those combinations, use base math to get the repetitive variations from 1 to 30. However, the number of elements within M might explode at 30. You might want to consider a lower number.
4 comentarios
K
el 13 de Ag. de 2014
Ahmet Cecen
el 13 de Ag. de 2014
Use cell structure to keep the C's. C{i} with curly brackets.
K
el 13 de Ag. de 2014
K
el 13 de Ag. de 2014
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!