readmatrix ignores the first line of the data file
조회 수: 104 (최근 30일)
이전 댓글 표시
I'm trying to read a text filw with over 226,600 rows with readmatrix (sample is over 5MB so I couldn't attach it here). The first line is numeric but readtable ignores the first line. Following is the line I'm using is follows, and I do require the structure (with NaN) that this provides.
data = readmatrix('sample.txt', 'Delimiter',' ','ConsecutiveDelimitersRule', 'join');
I found a similar thread where table2array was suggested, but I get the "Input argument must be a table." error. How can I rectify this?
** edit: A trimmed sample file is uploaded.
댓글 수: 2
Stephen23
2023년 3월 9일
"How can I rectify this?"
Did you try specifying the first data line, or the number of header lines, or any other related options?
Please trim the file down a bit and upload it here.
채택된 답변
Stephen23
2023년 3월 9일
편집: Stephen23
2023년 3월 9일
You can specify the RANGE as the starting row:
M = readmatrix('sample.txt', 'ConsecutiveDelimitersRule','join', 'Range',1)
I note that the data are arranged in blocks which span multiple lines. Note that if all files have a fixed, known format then you might consider using FSCANF to reads those blocks of data, giving one row per block, e.g.:
nmc = 15+12*4;
fmt = repmat('%f',1,nmc);
fid = fopen('sample.txt','rt');
mat = fscanf(fid,fmt,[nmc,Inf]).';
fclose(fid);
display(mat)
댓글 수: 0
추가 답변 (1개)
Sarvesh Kale
2023년 3월 9일
You can open the text file in notepad and insert some text that best describes your data on the first line, from second line your data will start and I guess this should resolve your problem
Thank you
참고 항목
카테고리
Help Center 및 File Exchange에서 Text Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!