Matlab: Perform a procedure only for specific character arrays

醉酒当歌 提交于 2021-01-29 10:41:20

问题


I have 60 different character arrays loaded in my workspace (Book01, Book02, ..., Book60). For example, Book01 is a 1x202040 char.

I'm working in a script file, and trying to separate the last sentence("RandomInfoAtEnd") of Book45 until Book58:

WholeBook = Book50; % Call Array for test

for i = 1:60
    book = eval(['Book' num2str(i)]);
    if i >= 45 && i <= 58
        % Procedure to separate last sentence.
        Chr = convertStringsToChars(WholeBook);
        SearchedUnit = '.!?' ;    % Sentence end punctuation
        idx = ismember (Chr, SearchedUnit); 
        Loc = find (idx, 2, 'last'); % Find second last sentence-ending-punctuation
            if numel (Loc) < 2
                error ('the requested character cannot be found')
            end
        SecondLastLocation = Loc (1);
        AllLocations = find (idx);
        RandomInfoAtEnd = extractAfter(WholeBook,SecondLastLocation);
    else
        RandomInfoAtEnd = ''; % No sentence separated
    end
end

Right now I have a problem only with the IF-statement or FOR-loop logic, in such a way that RandomInfoAtEnd = '' for any array that is called. My procedure is working fine, as it separated the last sentence perfectly from any array, but what am I doing wrong with the FOR-loop/IF-statement? Thanks.

来源:https://stackoverflow.com/questions/65643656/matlab-perform-a-procedure-only-for-specific-character-arrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!