Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

Matlab: Perform a procedure only for specific character arrays

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...