我读了Reading data from Dukascopy tick binary file的答案,但我在Matlab中遇到了麻烦。我基本上想从源文件中得到相同的答案。
到目前为止,我有:
fid=fopen(filename);
ii1=fread(fid,8,uint8,'b');
ii2=fread(fid,1,uint8,'b');
ii3=fread(fid,8,uint8,'b');
ff1=fread(fid,8,uint8,'b');
ff2=fread(fid,8,uint8,'b');
我无法获得正确的结果,即:
ii1=970
ii2=143040
ii3=143030
ff1=6.4
ff2=9.5
答案 0 :(得分:4)
你很亲密。假设您建议的结果是正确的,您需要这样做:
fid = fopen('12h_ticks');
ii1 = fread(fid,1,'int32','b'); % int32 or uint32
ii2 = fread(fid,1,'int32','b'); % int32 or uint32
ii3 = fread(fid,1,'int32','b'); % int32 or uint32
ff1 = fread(fid,1,'float32','b'); % single precision
ff2 = fread(fid,1,'float32','b'); % single precision
fclose(fid); % Don't forget to close the file
输出全部由fread
转换为双精度值。如果您希望将数据保留为其原始格式,则可以针对相关行执行此操作:
ii1 = fread(fid,1,'int32=>int32','b');
ii2 = fread(fid,1,'int32=>int32','b');
ii3 = fread(fid,1,'int32=>int32','b');
ff1 = fread(fid,1,'float32=>single','b');
ff2 = fread(fid,1,'float32=>single','b');
最后,由于这是Matlab,您可能希望将数据读入两个向量:
ii = fread(fid,3,'int32','b'); % 3-by-1 vector
ff = fread(fid,2,'float32','b'); % 2-by-1 vector