Filter löschen
Filter löschen

How to create a permutation table on Matlab?

7 Ansichten (letzte 30 Tage)
hang dong
hang dong am 14 Mai 2019
Kommentiert: hang dong am 15 Mai 2019
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 Kommentare
hang dong
hang dong am 14 Mai 2019
What function do you use to list permutations of a string of n elements?
Steven Lord
Steven Lord am 14 Mai 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

KSSV
KSSV am 14 Mai 2019
Bearbeitet: KSSV am 15 Mai 2019
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 Kommentare
Guillaume
Guillaume am 14 Mai 2019
"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 am 15 Mai 2019
KSSV. thank for supporting me!

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by