Reading 3rd set of data from large text file
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Daniel Armyr
2011년 12월 5일
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.
답변 (2개)
Fangjun Jiang
2011년 12월 5일
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
charles atlas
2011년 12월 5일
댓글 수: 2
Fangjun Jiang
2011년 12월 5일
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
2011년 12월 5일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!