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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

질문:

2014년 5월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by