Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
Juan Rosado
Juan Rosado le 22 Fév 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?

Réponses (1)

per isakson
per isakson le 22 Fév 2013
Modifié(e) : per isakson le 23 Fév 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).

Catégories

En savoir plus sur Large Files and Big Data dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by