Importdata; textheader not read completely

3 visualizaciones (últimos 30 días)
Mark
Mark el 12 de Mayo de 2016
Comentada: Walter Roberson el 8 de Jun. de 2016
I have a lot of data files like the ones attached. These were all read using the following line:
data = importdata(fullfile(pcsv,fcsvTemp));
This worked fine, until just recently when some of the files were not loaded correctly. I.e. the textheader at the start f the file is not read completely, and numeric data is not read at all (only 2x2 matrix instead of very long matrix) I really don't see any difference between the files in the header, can anyone help?

Respuestas (1)

Elias Gule
Elias Gule el 13 de Mayo de 2016
Try reading the file data into a string and use the textscan function to retrieve the data you want.
filename = '22P04a.csv';
filetext = fileread(filename);
data = textscan(filetext,'%f','HeaderLines',10); % returns a cell array of cells
data = cell2mat(data) % get the data as matrix
  2 comentarios
Mark
Mark el 8 de Jun. de 2016
Hi, First of all, thanks, it works well for the numeric data. However, the first lines are also important to me (retrieving subjectcodes, date etc.), and I would like to get these as a cell matrix (per line a cell). Using strsplit I can get each word, but not each line within a cell. Since header can vary slightly, it is quite important that i can read each line into a cell. Suggestions?
Walter Roberson
Walter Roberson el 8 de Jun. de 2016
filename = '22P04a.csv';
fid = fopen(filename, 'rt');
headers = textscan(fid, '%[^\n]', 10);
datacell = textscan(fid, '%f');
fclose(fid);
data = datacell{1};

Iniciar sesión para comentar.

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