Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
Juan Rosado
Juan Rosado el 22 de Feb. de 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?

Respuestas (1)

per isakson
per isakson el 22 de Feb. de 2013
Editada: per isakson el 23 de Feb. de 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).

Categorías

Más información sobre Large Files and Big Data en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by