필터 지우기
필터 지우기

How to get all the first five columns from a text file?

조회 수: 1 (최근 30일)
Juan Rosado
Juan Rosado 2013년 2월 22일
I am trying to get all the first five columns starting from the third row of this text five.
This is the text file,
This is the function I created,
function Data = SJ
fid = fopen( 'SJ.txt' );
Data = textscan( fid, '%d%d%d%d%d%f%f%f%f%f%s%s%s%f%f%f%f%f%f' ...
, 'Delimiter' , ' ' ...
, 'CollectOutput' , true ...
, 'HeaderLines' , 2 ...
, 'MultipleDelimsAsOne' , true ...
, 'Whitespace' , '' ...
);
fclose( fid );
end
Every time I run it I only get the first five columns of the third row stored on the Data{1,1} cell.
Can you please help?

답변 (1개)

per isakson
per isakson 2013년 2월 22일
편집: per isakson 2013년 2월 23일
Do you really mean "the first five columns"? That's only date and time. However, this format string does that
'%d%d%d%d%d%*[^\n]'
it says: read the first five columns and skip the rest of the row.
Alternative: Add the line
, 'TreatAsEmpty' , 'MM' ...
to textscan. All "MM" in numeric columns will be returned as NaN. Otherwise, reading stops at first "MM" in a numeric column (a column with "%f" in the format).

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by