Generate all permutation or possibilities
Show older comments
I'm still fairly new to MATLAB, but got thrown at with a homework on Huffman coding. It requires to take a word, break it down to each letter, generate the all the possibilities in 3rd, 4th, and 5th order. For instance, in my case, I picked the word 'locate', then strip it down to 'l' 'o' 'c' 'a' 't' 'e'. 3rd order means I'll generate all the possilities/combinations for 3 positions out of 6 letters like 'loc' 'loa' 'lot' etc.. Same concept goes as 4th and 5th order. I had tried nchoosek function, it only give me the combinations (order matter), not all permution or possibilities. I hope it makes sense. Any guidance will be appreciated.
Accepted Answer
More Answers (1)
s='locate'
n=3;
c=nchoosek(s,n);
c=reshape(c(:,perms(n:-1:1)')',n,[])'
1 Comment
Ben Nguyen
on 26 Oct 2022
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!