Pseudorandom character matrix generation

6 views (last 30 days)
Generate a 10x10 matrix with the letters 'b', 'd', 'p', 'q' in randomized order. Every refresh should produce a new randomized matrix.
This is to simulate the bdpq test. Should be a pretty simple task, but seems to be otherwise!

Accepted Answer

Rik
Rik on 29 Sep 2022
If you want a 10x10 char array, you can also use indexing:
source = 'bdpq';
Array = source(randi(end,[10 10]))
Array = 10×10 char array
'ppbbbbpbqd' 'pbpqpqdddb' 'pbqdddqbpb' 'dqppppqqbb' 'qbbbdbpqpd' 'qpbbqpqbbq' 'qqqpqdpqdp' 'pbqbppqqbp' 'dqdddpddqq' 'pdddpqdqpd'
  3 Comments
Rik
Rik on 30 Sep 2022
I can't say I understand what you want to do, so I don't have any suggestions. Your steps don't seem very complicated, so I don't expect to have a much better solution.

Sign in to comment.

More Answers (1)

KSSV
KSSV on 29 Sep 2022
s = {'b', 'd', 'p', 'q' } ;
S = cell(10) ;
for i = 1:10
for j = 1:10
t = s(randperm(4,4)) ;
S{i,j} = [t{:}] ;
end
end
S
S = 10×10 cell array
{'dbpq'} {'qbdp'} {'pdbq'} {'qpbd'} {'qbdp'} {'pqdb'} {'qbdp'} {'qpdb'} {'bqpd'} {'pbqd'} {'bqdp'} {'dpbq'} {'bpdq'} {'pbqd'} {'bdqp'} {'dbqp'} {'qpdb'} {'dpbq'} {'pbdq'} {'pbqd'} {'bpdq'} {'dpqb'} {'pqbd'} {'bqdp'} {'pqbd'} {'qdpb'} {'bqpd'} {'bdpq'} {'dbpq'} {'bpdq'} {'pdqb'} {'bpdq'} {'qdpb'} {'dpbq'} {'bqdp'} {'dqbp'} {'pbdq'} {'pdbq'} {'qpdb'} {'bqdp'} {'dbpq'} {'bpdq'} {'bpqd'} {'dqpb'} {'pdqb'} {'qdbp'} {'dqbp'} {'bpqd'} {'dpbq'} {'dbpq'} {'dqpb'} {'bdpq'} {'qpbd'} {'pbdq'} {'dqbp'} {'pqbd'} {'qpdb'} {'bdqp'} {'pdbq'} {'dbqp'} {'qdbp'} {'qdbp'} {'bpqd'} {'bpqd'} {'bqdp'} {'bpqd'} {'dbqp'} {'dqbp'} {'bpqd'} {'bpqd'} {'dpbq'} {'dpbq'} {'dbqp'} {'dqpb'} {'bdpq'} {'qbdp'} {'bdpq'} {'pdqb'} {'qpdb'} {'bdpq'} {'qbdp'} {'dbqp'} {'pqbd'} {'qpdb'} {'bdqp'} {'bpdq'} {'pbdq'} {'pqbd'} {'dbqp'} {'pdqb'} {'pqdb'} {'dbqp'} {'bpdq'} {'dqpb'} {'dpbq'} {'qbpd'} {'bpdq'} {'pbdq'} {'qpdb'} {'pdqb'}

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by