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

1 次查看(过去 30 天)
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 中查找有关 Data Import and Export 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by