Reading 3rd set of data from large text file

10 views (last 30 days)
I have a large set of data that I am reading from a .lis file. There are 3 lines of header data, then a few thousand lines of numeric data in two columns. Then there are 5 lines of header data with numeric data below that in 9 columns. Finally there are 5 more lines of header data with 8 columns of numeric data below that.
I have a code that currently reads the first two columns of data. I am not sure however, how you would read the 3rd set of data. That is the 8 columns of data right below the 3rd set of header lines. Does anyone know how I would do this?
The .lis file looks like this:
Column (of temp data), Column (of height data)
Headerline (x5)
9 columns of numeric data
Headerline (x5)
8 columns of numeric data
note: all of the data is seperated by spaces
charles atlas
charles atlas on 5 Dec 2011
fid = fopen('data.lis','rt');
XX = textscan(fid,'%f%f','HeaderLines',3);
tempA=XX{:,1}; heightA=XX{:,2};

Sign in to comment.

Answers (2)

Fangjun Jiang
Fangjun Jiang on 5 Dec 2011
It can be done but it will largely depends on the actual data format, data length of your file. It's really hard to make it generic.
If this process is an one-time thing, maybe you can consider doing it through Excel. You can open the .lis file using Excel. It will go through a dialog. You can choose to use space as the delimiter.
Once the Excel file is created, you can use xlsread() to read all the data at once and then process it. See what are returned in the text and numerical data using [Num, Txt, Raw]=xlsread(). In the worst case, it's probably easier once you get all the data in the cell array Raw.
Or you can use Data=uiimport('MyData.xls'). Once you finish the dialog, you have the option to generate the code for the uiimport() processing that you've done.

charles atlas
charles atlas on 5 Dec 2011
Is there any way to have a code that cycles through the text file and says once you see numeric data is 8 columns (skipping the 9 columns of data section) then read that data into an array?)
or being that the 8 columns of data is the only data labeled as "HEIGHT PROFILE STATISTICS", there might be a code that would serch for that specific line of text, and then read the 8 columns of data 4 headerlines below it?
Walter Roberson
Walter Roberson on 5 Dec 2011
You could also try
Datafields = regexp(line, ' ', 'split');
length(Datafields) would then be the number of fields, and
str2double(DataFields) would be the numeric content of the fields.
In theory this should be faster than doing the numeric conversions and counting the results, but in practice it could go either way, as the scanning routines are quite optimized.

Sign in to comment.



Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by