0

I read the answers to Reading data from Dukascopy tick binary file, but I'm having trouble doing it in Matlab. I essentially want the same answers from the source file.

So far, I have:

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');

I'm having difficulty getting the right results, that is:

ii1=970
ii2=143040
ii3=143030
ff1=6.4
ff2=9.5
Community
  • 1
  • 1

1 Answers1

4

You're close. Assumming that the results you suggest are the correct ones, you need to do this:

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

The outputs are all converted to double precision values by fread. If you want to keep the data in its native format you can do this instead for the relevant lines:

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');

Finally, since this is Matlab, you might want to read in the data as two vectors:

ii = fread(fid,3,'int32','b');   % 3-by-1 vector
ff = fread(fid,2,'float32','b'); % 2-by-1 vector
horchler
  • 18,384
  • 4
  • 37
  • 73