all the substrings of a given string S

Howdy everyone, I need to select all the substrings available from a given string S. By substring I mean any S(i:j), with j <= length(S) and i<=j. I wrote the following working code:
if true
voc{1}='';
cont=2;
for i=1:length(string)
for j=i:length(string)
voc{cont}=string(i:j);
cont=cont+1;
end
end
voc=unique(voc);
end
The variable voc contains all the substrings plus the element '' in the first position. I would need something faster than this. Any suggestion is appreciated. Thanks in advance

Answers (0)

Categories

Asked:

on 13 May 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!