How do I take my generated string outputs from for loop and return a list?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Brandon Tsang
am 19 Jan. 2023
Bearbeitet: Stephen23
am 19 Jan. 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 Kommentare
Akzeptierte Antwort
Walter Roberson
am 19 Jan. 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 Kommentare
Weitere Antworten (1)
Sulaymon Eshkabilov
am 19 Jan. 2023
Here si the solution:
a=[];
seq = 'ACAUUUGCUUCUGACACAACUGUGUUCACUAGCAACCUCAAACAGACA'
for i=1:3:numel(seq)-2
a = [a; (seq(i:i+2))];
end
a
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!