all the substrings of a given string S

1 view (last 30 days)
Martino
Martino on 13 May 2014
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

Find more on Startup and Shutdown 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!