The working of perms
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I tried perms('abc'). The doc says it is permutations in reverse lexicographic order. So I expected from the bottom - abc, acb, bac, bca so on. But the result I got was acb, abc, bac, bca ..... Can any one explain what is going on?
0 Kommentare
Antworten (2)
Thorsten
am 15 Okt. 2015
Have a look at
perms(1:3)
The result you get with perms('abc') is analogous to this. To have lexicographic order, use
sortrows(perms('abc'))
2 Kommentare
Jan
am 18 Okt. 2015
Bearbeitet: Jan
am 18 Okt. 2015
With Matlab R2011b I get:
perms('abc')
cba
cab
bca
bac
abc
acb
As reversed alphabetical order, I'd expect the last two lines to be swapped.
An efficient method to create the permutations in a sorted order: FEX: VChooseKO. But here the order is not "alphabetically" accoring to the contents of the input, but to the order of the values. So for an alphabetical order you'd need:
Str = 'acb';
VChooseKO(sort(Str), length(Str))
0 Kommentare
Siehe auch
Kategorien
Mehr zu Octave finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!