Borrar filtros
Borrar filtros

read data from csv file & fast processing

1 visualización (últimos 30 días)
shaz
shaz el 7 de Nov. de 2012
i have a data like which is read from csv file like
10;20;2;3;45;56;87;56;988;434;10;20;2;3;45;56;87;56;988;434
i have 9lakhs of data like this what is best way to separate by ; & form a matrix
because now it is consuming to much of time
Thanks in advance
  12 comentarios
shaz
shaz el 8 de Nov. de 2012
Editada: Walter Roberson el 8 de Nov. de 2012
a;b;c;d;f;g;i;p;t;r;l;e;r;y;u % Headers
10;20;2;3;4.5;56;87;56;988;434;10;20;2;3;45;56;87;56;988;434
10;20;2;3;4.5;56;87;56;988;434;10;20;2;3;45;56;87;56;988;434
10;20;2;3;45;56;87;56;988;434;10;20;2;3;45;56;87;56;988;434
....................% data
.....................% data
like wise we have 9 lakh rows(900000 rows) of data & one row of header
now how to get the headers in cell format(1st row) & rest data in matrix format
Jan
Jan el 27 de Nov. de 2012
@shaz: Although it looks obvious, that you neither read the comments nor care about them: Please stop using the term "lakh" without any further explanations, because it is not part of the English language such that it might confuse the readers. It is very friendly that Per explained this, but this has been your your turn actually.
Can you imagine the effects, when you do not care about questions for clarifications?

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 7 de Nov. de 2012
Editada: Jan el 8 de Nov. de 2012
fid = fopen(FileName, 'r');
if fid == -1, error('Cannot open file!'); end
header = fgetl(fid); % Read header line
pos = ftell(fid); % Store position [EDITED: fseek -> ftell]
line1 = fgetl(fid); % first data line
data = sscanf(line1, '%g;', Inf);
ncol = length(data);
fmt = repmat('%g; ', 1, ncol);
fseek(fid, pos, 'bof'); % Restore file position
data = fscanf(fid, fmt, Inf);
data = transpose(reshape(data, ncol, []));
fclose(fid);
Please check the reshape and transpose, if it satisfies your needs.
  3 comentarios
Jan
Jan el 27 de Nov. de 2012
Does this comment contain a question?
shaz
shaz el 10 de Dic. de 2012
@simon: thanks for the support...great

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Low-Level File I/O 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