Pseudorandom character matrix generation

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!

 Réponse acceptée

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 commentaires

Abhraneil
Abhraneil le 30 Sep 2022
Hi @Rik, I am trying to use this code for an app in matlab app deisgner. I tried to use a Table, Text Area, and Edit Field (Text), Edit Field (Numeric) to show the output in the app's UI, but everytime I receive the error " Conversoin to matlab.ui.control.<display type> from char is not possible. Any idea to resolve this conversion issue?
Thanks!
Abhraneil
Abhraneil le 30 Sep 2022
Hi @Rik, I used Table in the app UI, and I added "array2table" to Array, and it produced a clean output. So it seems to be working.
If you have any better suggestions, please let me know! Thank you!
Rik
Rik le 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.

Connectez-vous pour commenter.

Plus de réponses (1)

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'}

Catégories

En savoir plus sur Random Number Generation dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by