필터 지우기
필터 지우기

read data from csv file & fast processing

조회 수: 1 (최근 30일)
shaz
shaz 2012년 11월 7일
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
shaz
shaz 2012년 11월 8일
편집: Walter Roberson 2012년 11월 8일
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 2012년 11월 27일
@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?

댓글을 달려면 로그인하십시오.

채택된 답변

Jan
Jan 2012년 11월 7일
편집: Jan 2012년 11월 8일
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
Jan
Jan 2012년 11월 27일
Does this comment contain a question?
shaz
shaz 2012년 12월 10일
@simon: thanks for the support...great

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Low-Level File I/O에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by