View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
All Permutations of integers with sum criteria

5.0 | 9 ratings Rate this file 9 Downloads (last 30 days) File Size: 2.64 KB File ID: #17818 Version: 1.5

All Permutations of integers with sum criteria


Bruno Luong (view profile)


30 Nov 2007 (Updated )

All Pernutations of integers with sum criteria

| Watch this File

File Information

This function provides all combinations of integer vector that must verify a criteria on the sum.

Supported criteria is
sum(v) == L1
sum(v) <= L1
sum(v) < L1

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (10)
17 May 2016 Arnfinn Aas Eielsen

22 May 2014 Bruno Luong

Bruno Luong (view profile)

@ Jang: the number of combination grows fast, like a factorial (i.e., more than a exponential). So it is not surprising that your computer (or any computer in fact) won't handle well large value.

Comment only
16 May 2014 Han Seung Jang

Thanks for your great work!!
It is very useful function program.
I have a question.
I checked allVL1(64,1), allVL1(64,2), allVL1(64,3) and allVL1(64,4) worked.
However, for large number n and L1, for example, allVL1(64,5), it gives errors and sometimes computer stops.
MATLAB cannot support large numbers n and L1, for allVL1(n,L1)?

16 May 2014 Han Seung Jang

14 Oct 2013 Andrew Jones

08 Apr 2013 Daesang Kim

05 Sep 2012 Hsuan-Yin

21 Sep 2009 Ben Petschel

Nice program. Users might also be interested in a looped solution using the function "nextwhile" in the NextVector toolbox <pre class="link"></pre>. If the entire matrix of combinations is needed then Bruno's version is faster (because row concatenation is slow) otherwise the looped solution is faster.

05 Mar 2008 Greg von Winckel

Great stuff. I used your work in my code that I just submitted here, but forgot to give credit. I will fix that as soon as I can modify the entry. Thanks for your help!

13 Dec 2007 John D'Errico

A slick solution to this problem, that uses an elegant recursive code for its work.

Good help, error checks, defaults for arguments where they apply. One minor flaw that I'll hope the author fixes. There is no H1 line. An H1 line is the first line of help. It should be a descriptive line that the function lookfor keys on, including all reasonable keywords that you might search on.

Lookfor is useful when you need to find this function in a year. Will you remember the name "allVL1" next year? No, probably not. But lookfor will find this function for you, if you supply an H1 line.

18 May 2009 1.1

Possibility to get the number of permutations to check feasibility

16 Sep 2009 1.2

Correct a bug when the number of solutions is inquired

18 Dec 2010 1.5

+ non-recursive engine

Contact us