The working of perms

조회 수: 6 (최근 30일)
Seetha Rama Raju Sanapala
Seetha Rama Raju Sanapala 2015년 10월 15일
편집: Jan 2015년 10월 18일
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?

답변 (2개)

Thorsten
Thorsten 2015년 10월 15일
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
Guillaume
Guillaume 2015년 10월 15일
편집: Guillaume 2015년 10월 15일
But the OP is correct. The doc is wrong and the order returned by perms is not reverse lexicograph.
For what it's worth, I've reported it to mathworks.
... and it's now been acknowledged as a bug.
Seetha Rama Raju Sanapala
Seetha Rama Raju Sanapala 2015년 10월 18일
@Guillaume. Thank you.

댓글을 달려면 로그인하십시오.


Jan
Jan 2015년 10월 18일
편집: Jan 2015년 10월 18일
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))

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by