Difference between revisions of "Unique perms"

From QETLAB
Jump to navigation Jump to search
(Created page with "{{Function |name=unique_perms |desc=Computes the unique permutations of a vector |upd=November 27, 2014 |cat=Helper functions |lic=1 |he...")
 
(Function removed)
 
(2 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
|lic=1
 
|lic=1
 
|helper=1}}
 
|helper=1}}
 +
{| class="wikitable"
 +
|-
 +
! FUNTION REMOVED
 +
|-
 +
| 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.
 +
|}
 
<tt>'''unique_perms'''</tt> is a [[List of functions|function]] that computes all distinct permutations of a vector. Thus is produces the same output as using the built-in MATLAB commands <tt>unique(perms(V),'rows')</tt>, but it is significantly faster if there are many repetitions in the vector.
 
<tt>'''unique_perms'''</tt> is a [[List of functions|function]] that computes all distinct permutations of a vector. Thus is produces the same output as using the built-in MATLAB commands <tt>unique(perms(V),'rows')</tt>, but it is significantly faster if there are many repetitions in the vector.
  
Line 15: Line 21:
  
 
==Examples==
 
==Examples==
The following generates all unique permutations of the vector <tt>[1,1,2,2,1,2,1,3,3,3]</tt> in two different ways: using this <tt>unique_perms</tt> function, and by using matlab's built-in [http://www.mathworks.com/help/matlab/ref/unique.html unique] and [http://www.mathworks.com/help/matlab/ref/perms.html perms] functions. Using the <tt>unique_perms</tt> function is much faster than the vector has lots of repetitions (as in this case).
+
The following generates all unique permutations of the vector <tt>[1,1,2,2,1,2,1,3,3,3]</tt> in two different ways: using this <tt>unique_perms</tt> function, and by using matlab's built-in [http://www.mathworks.com/help/matlab/ref/unique.html unique] and [http://www.mathworks.com/help/matlab/ref/perms.html perms] functions. Using the <tt>unique_perms</tt> function is much faster when the vector has lots of repetitions (as in this case).
 
<syntaxhighlight>
 
<syntaxhighlight>
 
>> v = [1,1,2,2,1,2,1,3,3,3];
 
>> v = [1,1,2,2,1,2,1,3,3,3];

Latest revision as of 01:13, 1 August 2023

unique_perms
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.
FUNTION REMOVED
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.

Syntax

  • PERM_LIST = unique_perms(V)

Argument descriptions

  • V: The vector to be permuted.

Examples

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
   toc

ans =

        4200

Elapsed time is 0.300853 seconds.

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

ans =

        4200

Elapsed time is 4.559448 seconds.

Source code

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

External links