How to make a character array from loop output?

7 visualizaciones (últimos 30 días)
Aniston Gnana
Aniston Gnana el 8 de Nov. de 2017
Comentada: Aniston Gnana el 9 de Nov. de 2017
The function is mean't to generate nine random DNA sequence of different lengths (between 4 and 6 letters long), I am then supposed to sort these in alphabetical order. I'm having trouble adding the different output iterations of my loop into an array so that I can use "sort" to sort them alphabetically.
if true
function dna = SeqGen
%Randomly generates a sequence of DNA 9 times
for i = 1:9
k = randi([4,6],1);
seq = randseq(k ,'Alphabet', 'dna');
end
end
I'm not sure if i'm supposed to use char() or something else.

Respuesta aceptada

KL
KL el 8 de Nov. de 2017
Editada: KL el 9 de Nov. de 2017
store them in a cell array,
seq = cell(1,9);
for m = 1:9
k(m) = randi([4,6],1);
seq{m} = randseq(k(m) ,'Alphabet', 'dna');
end
  4 comentarios
Guillaume
Guillaume el 9 de Nov. de 2017
"not sure what you mean by store them in array"
KL wrote store them in a cell array. cell being the key word. See the doc. In particular, the second sentence says:
"Cell arrays commonly contain [...] arrays of different sizes"
Aniston Gnana
Aniston Gnana el 9 de Nov. de 2017
got it thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by