How to make a character array from loop output?

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.

 채택된 답변

KL
KL 2017년 11월 8일
편집: KL 2017년 11월 9일

0 개 추천

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

not sure what you mean by store them in array
Did you try the code I gave you? You should create a cell array and pre-allocate it with the size you want.
seq = cell(1,9);
and the use it inside you loop like
seq{m} %m =1,2,3...9
Guillaume
Guillaume 2017년 11월 9일
"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"
got it thank you

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

질문:

2017년 11월 8일

댓글:

2017년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by