How to create a permutation table on Matlab?

Hello every one. My name is Hang.
I'm working on a graduation project, I have a little bit of hope for people to help me.
I want to create a table containing all permutations of a string of n elements, a table to index each permutation of that string. everyone help me. Thanks everyone!

댓글 수: 3

madhan ravi
madhan ravi 2019년 5월 14일
What have you tried?
hang dong
hang dong 2019년 5월 14일
What function do you use to list permutations of a string of n elements?
Steven Lord
Steven Lord 2019년 5월 14일
How large a value of n are you planning to use? As the documentation states, the perms function is practical only for small vectors as the resulting matrix is of size [factorial(n), n] and that grows pretty quickly. Your matrix will have over three million rows for n = 10 and over six billion for n = 13.

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

답변 (1개)

KSSV
KSSV 2019년 5월 14일
편집: KSSV 2019년 5월 15일

0 개 추천

Read about perms.
str = 'MATLAB' ;
id = 1:length(str) ; % indices
ids = perms(id) ; % permuted indices
iwant = str(ids) ; % permuted string
pos = (1:length(iwant))' ;
T = table(pos,iwant) ; % convers to table
writetable(T,'test.xlsx') % write table to file

댓글 수: 8

hang dong
hang dong 2019년 5월 14일
sorry. I want to record the permutation result into a file, index each permutation, then use this result to perform another math formula
hang dong
hang dong 2019년 5월 14일
The index of permutations is in the range of 0 -> n - 1
KSSV
KSSV 2019년 5월 14일
Edited the code...now it will give indices also.
hang dong
hang dong 2019년 5월 14일
thank for supporting me!
KSSV
KSSV 2019년 5월 14일
Thank you is accepting the answer. :)
hang dong
hang dong 2019년 5월 14일
I want the results shown as follows:
indices permuted
0 MATLAB
1 MTALAB
...
719 BALATM
Guillaume
Guillaume 2019년 5월 14일
"I want ..."
Yes, so what's preventing you from doing that very trivial modification to KSSV's code? If you don't know how to construct a table, perhaps you should learn this from the documentation. If you don't know how to construct a vector of integers, perhaps you should learn to use matlab first.
hang dong
hang dong 2019년 5월 15일
KSSV. thank for supporting me!

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2019년 5월 14일

댓글:

2019년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by