Question 7 Libraries
During the course we wrote a program to generate all the permutations of an ar- ray of characters. For example, given ’part’, our script printed the permutations: tarp, trap, prat, etc. MATLAB has a library function perms. Typing: help perms gives the following output:
>> help perms
perms All possible permutations.
perms(1:N), or perms(V) where V is a vector of length N, creates a matrix with N! rows and N columns containing all possible permutations of the N elements.
This function is only practical for situations where N is less than about 10 (for N=11, the output takes over 3 gigabytes).
Class support for input V:
float: double, single
integer: uint8, int8, uint16, int16, uint32, int32, uint64, int64
logical, char
See also nchoosek, randperm, permute.
Reference page for perms
Given an array of characters word = ’hello’; write the MATLAB code needed to generate and display all of the permutations of word using the perms function.
[3 marks]
[Total for Question 7: 3 marks]