MATLAB:如何根据循环数字划分字符串

MATLAB: How to divide up a string according to a recurring number

美好的一天。

下面是我要分的一个识字的例子:

str =      ["1 This is sentence one of verse one, "+ ...
            "2 This is sentence one of verse two. "+ ...
            "3 This is sentence two of verse three; "+ ...
            "1 This is sentence three of verse one? "+ ...
            "2 This is sentence four of verse two, "+ ...
            "3 this is sentence four but verse three!"];

注意数字是如何重新开始的,这表示新的章节开始了。我怎样才能制作一个 nx1 字符串,其中 n=chapters.结果应该是这样的:

感谢您的帮助。 谢谢!

您只需要一点点字符串操作:

>> c=convertStringsToChars(str);
>> splitstring = split(str,c(1));
>> splitstring = splitstring(strlength(splitstring) > 0);
>> formattedstring = string(1:length(splitstring)).' + " " + c(1) + splitstring

formattedstring = 

  2×1 string array

    "1 1 This is sentence one of verse one, 2 This is sentence one of verse two. 3 This is sentence two of verse three; "
    "2 1 This is sentence three of verse one? 2 This is sentence four of verse two, 3 this is sentence four but verse three!"