Unique perms

Jump to navigation Jump to search
Computes the unique permutations of a vector

Other toolboxes required none
Function category Helper functions
License license_unique_perms.txt
This is a helper function that only exists to aid other functions in QETLAB. If you are an end-user of QETLAB, you likely will never have a reason to use this function.
This function was removed from QETLAB between versions 0.9 and 1.0, as it is no longer needed by QETLAB's core functions. The documentation below is for the version 0.9 version of this function, and will be kept as-is in case it can be useful for users of old versions of QETLAB.

unique_perms is a function that computes all distinct permutations of a vector. Thus is produces the same output as using the built-in MATLAB commands unique(perms(V),'rows'), but it is significantly faster if there are many repetitions in the vector.


  • PERM_LIST = unique_perms(V)

Argument descriptions

  • V: The vector to be permuted.


The following generates all unique permutations of the vector [1,1,2,2,1,2,1,3,3,3] in two different ways: using this unique_perms function, and by using matlab's built-in unique and perms functions. Using the unique_perms function is much faster when the vector has lots of repetitions (as in this case).

>> v = [1,1,2,2,1,2,1,3,3,3];
>> tic; length(unique_perms(v)) % fast method

ans =


Elapsed time is 0.300853 seconds.

>> tic; length(unique(perms(v),'rows')) % slow method

ans =


Elapsed time is 4.559448 seconds.

Source code

Click here to view this function's source code on github.

External links