fprintf尺寸限制

时间:2017-07-25 09:26:02

标签: matlab text printf

在matlab中使用fprintf时,我遇到了一个问题。我正在写一个像这样的大字符数组:

import java.io.Serializable;

public class SimpleClass implements Serializable {    
    private static final long serialVersionUID = -9062339996046009959L;
    public byte Byte;
    public int id;

    public SimpleClass(byte Byte, int id) {
        this.Byte = Byte;
        this.id = id;
    }
}

当输出任何小于1GB的文本文件时,它似乎工作,但是过去会导致输出文件为空(0字节)。我相信这可能是一个32位的限制。这是否正确,如果有,是否有任何解决方法?

感谢任何帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

我无法重现你的问题。此脚本将2GB的textdata写入test.txt并运行且没有错误。我在Windows 7 64位上使用matlab 2017a。 (确实需要43秒)

st = char(randi([0 255],[1,2^31],'uint8')); %2GB of textdata
fileID = fopen('test.txt','w');                                  
fprintf(fileID,'%s',st);                             
fclose(fileID);

让我感到惊讶的是,matlab每个字符值使用2个字节。

相关问题