0

I am trying to read a file with 5 entries for each line, two of which are float and the others are integers. However, fscanf function of matlab only reads two rows, and I guess it's a memory problem (for just 5k lines of data?).

Do you know how to fix this?

4

1 回答 1

0

我怀疑它是一个内存问题。也许您的输入文件中有一些意想不到的字符?你能重现以下内容吗?

输入.txt

3.4E-5 4.2E14 1475 381 998877
3.4E-5 4.2E14 1475 381 998877
3.4E-5 4.2E14 1475 381 998877
3.4E-5 4.2E14 1475 381 998877
3.4E-5 4.2E14 1475 381 998877

结束输入.txt

filename='input.txt';
fid = fopen(filename);
A = fscanf(fid, '%f %f %d %d %d', [5 inf])';
fclose(fid);


>> A(:,1)

ans =

  1.0e-004 *

    0.3400
    0.3400
    0.3400
    0.3400
    0.3400

>> A(:,5)

ans =

    998877
    998877
    998877
    998877
    998877

请小心,因为我很确定在使用具有多种数字类型的 fscanf 时,所有数字都会被翻倍。

>> class(A(:,5))

ans =

 double
于 2012-04-24T10:08:30.617 回答