Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Juan Rosado
Juan Rosado am 22 Feb. 2013
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?

Antworten (1)

per isakson
per isakson am 22 Feb. 2013
Bearbeitet: per isakson am 23 Feb. 2013
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).

Kategorien

Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by