How do I take my generated string outputs from for loop and return a list?
조회 수: 1 (최근 30일)
이전 댓글 표시
seq = 'ACAUUUGCUUCUGACACAACUGUGUUCACUAGCAACCUCAAACAGACA'
for i=1:3:numel(seq)-2
a = (seq(i:i+2))
end
a = 'ACA'
a = 'UUU'
a = 'GCU'
a = 'GAC'
etc...
% Desired output --> ['ACA', 'UUU', 'GCU', 'GAC' ...]
댓글 수: 0
채택된 답변
Walter Roberson
2023년 1월 19일
You should be careful what you ask for. 'ACA' is the 1 x 3 char vector ['A' 'C' 'A'] and ['ACA' 'UUU'] is concatenating two 1 x 3 vectors together getting a 1 x 6 vector 'ACAUUU' -- back to where you started
seq = 'ACAUUUGCUUCUGACACAACUGUGUUCACUAGCAACCUCAAACAGACA'
a1 = [];
a2 = cell(0);
for i=1:3:numel(seq)-2
a1 = [a1, seq(i:i+2)];
a2{end+1} = seq(i:i+2);
end
a1
a2
a3 = reshape(seq, 3, []).'
I would suggest to you that the a3 method is easiest. You might want to cellstr() or string() the resutling 16x3 array.
댓글 수: 0
추가 답변 (1개)
Sulaymon Eshkabilov
2023년 1월 19일
Here si the solution:
a=[];
seq = 'ACAUUUGCUUCUGACACAACUGUGUUCACUAGCAACCUCAAACAGACA'
for i=1:3:numel(seq)-2
a = [a; (seq(i:i+2))];
end
a
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!