How do I take my generated string outputs from for loop and return a list?
Show older comments
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' ...]
Accepted Answer
More Answers (1)
Here si the solution:
a=[];
seq = 'ACAUUUGCUUCUGACACAACUGUGUUCACUAGCAACCUCAAACAGACA'
for i=1:3:numel(seq)-2
a = [a; (seq(i:i+2))];
end
a
1 Comment
It is inefficient to keep expanding an array in a loop like that.
Simpler and much more efficient:
seq = 'ACAUUUGCUUCUGACACAACUGUGUUCACUAGCAACCUCAAACAGACA';
mat = reshape(seq,3,[]).'
Categories
Find more on Matrix Indexing 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!