How can i seperate a string in all possible smaller ones without using for loops;.
1 view (last 30 days)
Show older comments
zafeirios krommidas
on 23 Apr 2019
Commented: zafeirios krommidas
on 23 Apr 2019
For example if my string is a='ATGCA' , i want to make b={'AT', 'TG', 'GC', 'CA'}.( the length of the smaller strings is random, it may be three or four in this example.)
0 Comments
Accepted Answer
Stephen23
on 23 Apr 2019
>> a = 'ATGCA';
>> n = 2;
>> x = hankel(1:n,n:numel(a)).';
>> b = num2cell(a(x),2)
b =
'AT'
'TG'
'GC'
'CA'
More Answers (1)
Andrei Bobrov
on 23 Apr 2019
Edited: Andrei Bobrov
on 23 Apr 2019
a = 'ATGCA';
out = cellstr(a((1:end-1)' + [0, 1]));
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements 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!