Reading 3rd set of data from large text file
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Daniel Armyr
am 5 Dez. 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.
Antworten (2)
Fangjun Jiang
am 5 Dez. 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.
0 Kommentare
charles atlas
am 5 Dez. 2011
2 Kommentare
Fangjun Jiang
am 5 Dez. 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
am 5 Dez. 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.
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!