Reading 3rd set of data from large text file

4 visualizaciones (últimos 30 días)
charles atlas
charles atlas el 5 de Dic. de 2011
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:
Headerline
Headerline
Headerline
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
  2 comentarios
Daniel Armyr
Daniel Armyr el 5 de Dic. de 2011
Could you share the code you have to rad the first part of the data. Depending on which solution you have chosen for that, the solution for reading the rest of the data varies.
charles atlas
charles atlas el 5 de Dic. de 2011
fid = fopen('data.lis','rt');
XX = textscan(fid,'%f%f','HeaderLines',3);
tempA=XX{:,1}; heightA=XX{:,2};

Iniciar sesión para comentar.

Respuestas (2)

Fangjun Jiang
Fangjun Jiang el 5 de Dic. de 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 el 5 de Dic. de 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?
  2 comentarios
Fangjun Jiang
Fangjun Jiang el 5 de Dic. de 2011
Yes, you could.
use line=fgetl() to read each line
use Data=textscan(line,'%f') to count how many numerical data in a line.
Walter Roberson
Walter Roberson el 5 de Dic. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by