Reading Whole Lines of Text from a File
Sometimes the text files I need to read have an irregular format, i.e. it changes row-to-row. MATLAB file reading functions that expect columns of data (e.g readtable), need a uniform format to work. So if this is not the case, you need to read the file line-by-line, then split the lines/rows up into separate elements inside MATLAB. This gives you the ability to handle structure of any complexity.
My colleague Jeremy, who works on MATLAB file I/O, recommended these parameters to use as the safest way to read in text files a line at a time:
Play the video in full screen mode for a better viewing experience.
Format = '%[^\r\n]', Delimiter = '' and EndOfLine = '\r\n',In this code-along style video, I try to read a large text file using this method and making use of these functions:
- textscan
- contains, split, exractBefore
- datetime
评论
要发表评论,请点击 此处 登录到您的 MathWorks 帐户或创建一个新帐户。