MATLAB: Reading files containing sentences

reading files containing sentences

I have a file by name test_sents.txt (I'm attaching the file to this post). The file contains 3 sentences which are delimited by a '.' . I need to read each sentence (the sentences are of different lengths). Can anyone please help me with reading these sentences and storing it in some variable X.

Best Answer

S = fileread('test_sents.txt');
X = regexp(S, '\.', 'split');
Note that this will preserve carriage returns and newlines, since you indicated that the delimiter is '.' not CR or LF.
Also note that this is not sufficient for sentences that contain abbreviations or decimal values or ellipsis that has been entered as '...'
Related Question