How do I take my generated string outputs from for loop and return a list?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Brandon Tsang
el 19 de En. de 2023
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 comentarios
Respuesta aceptada
Walter Roberson
el 19 de En. de 2023
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 comentarios
Más respuestas (1)
Sulaymon Eshkabilov
el 19 de En. de 2023
Here si the solution:
a=[];
seq = 'ACAUUUGCUUCUGACACAACUGUGUUCACUAGCAACCUCAAACAGACA'
for i=1:3:numel(seq)-2
a = [a; (seq(i:i+2))];
end
a
Ver también
Categorías
Más información sobre Matrix Indexing 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!