How to read data from a .dat file row by row

A very large data file with .dat is to be read and loaded which contains a first row consisting of some characters as the head and a table containing 10,000 rows times 10,000 columns, whose data is in cell form.
I now want to restore the first row as a vector, say 'head',each entry being a string of characters, and the rest is a matrix A, each of whose elements are characters but in cell format originally.
Thanks!

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Sept. de 2016
If the .dat is in a well structured text format, then:
ncol = 10000;
sep = ',' ; %could be '\t' or other separator
hfmt = repmat('%s', 1, ncol);
cfmt = repmat('%f', 1, ncol);
fid = fopen('YourFileNameGoesHere.dat', 'rt');
head = textscan(fid, hfmt, 1, 'Delimiter', sep, 'Whitespace', '');
A = textscan(fid, cfmt, 'Delimiter', sep, 'Whitespace', '');
fclose(fid);
You would need to adjust the formats and separator.

Categorías

Más información sobre Data Import and Analysis en Centro de ayuda y File Exchange.

Preguntada:

el 19 de Sept. de 2016

Respondida:

el 19 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by