Cookbook: Difference between revisions

Jump to navigation Jump to search
632 bytes added ,  9 March 2013
→‎Combinatorics: Combinations with string characters
(new section for combinatorics with problem permutations with repetition)
(→‎Combinatorics: Combinations with string characters)
Line 143: Line 143:


== Combinatorics ==
== Combinatorics ==
=== Combinations with string characters ===
==== Problem ====
You want to get all combinations of different letters but {{codeline|nchoosek}} only accepts numeric input.
==== Solution ====
Convert your string to numbers and then back to characters.
{{Code||<syntaxhighlight lang="octave">
char (nchoosek (uint8 (string), n)
</syntaxhighlight>}}
==== Discussion ====
A string in Octave is just a character matrix and can easily be converted to numeric form back and forth. Each character has an associated number (the {{codeline|asci}} function of the {{forge|miscellaneous}} package displays a nicely formatted conversion table).
=== Permutations with repetition ===
=== Permutations with repetition ===
==== Problem ====
==== Problem ====
Line 162: Line 175:
combs = cell2mat (cellfun (@(c) c(:), cart, "UniformOutput", false));
combs = cell2mat (cellfun (@(c) c(:), cart, "UniformOutput", false));
</syntaxhighlight>}}
</syntaxhighlight>}}


== Mathematics ==
== Mathematics ==

Navigation menu