フィルターのクリア

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 Center および File ExchangeLow-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