How can i seperate a string in all possible smaller ones without using for loops;.

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.)

 Accepted Answer

>> a = 'ATGCA';
>> n = 2;
>> x = hankel(1:n,n:numel(a)).';
>> b = num2cell(a(x),2)
b =
'AT'
'TG'
'GC'
'CA'

More Answers (1)

a = 'ATGCA';
out = cellstr(a((1:end-1)' + [0, 1]));

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!