Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我必须用 MATLAB 中的程序生成的顽固分子测试一些“随机数”。Diehard 只接受 32 位二进制文件(单精度),但如果我将数据保存在 MATLAB 中,它会保存在双精度二进制文件中(因此 2*64 = 128 位二进制文件)。如何在 MATLAB 中创建 32 位二进制文件,在 64 位系统上工作?
如果您想以特定格式将数据读/写到二进制文件,您应该使用函数FREAD / FWRITE。例如,这会将 100 个随机值作为 32 位浮点数写入文件:
A = rand(1,100); fid = fopen('temp.dat','wb'); fwrite(fid,A,'float32'); fclose(fid);
有关 MATLAB 中文件 IO 的更多信息,您还可以查看这些其他相关的 SO 帖子:此处和此处。
除了 gnovice 的解决方案,您可能希望将随机数生成为“单个”,如下所示:
rand(1, 100, 'single')