title: Reading binary file into matlab
body: <p>I have a data file that uses (char(1 byte), char[n](array of n chars), word(2 byte unsigned int), short(2 byte signed int), dword(4 byte unsigned int), long(4 byte signed int) and float(4 byte real)) and is supposedly in the following format. I am reading the data file into MATLAB with fopen, fread, etc. but the values I am getting are not what I expect. </p>
  
  <p>Format:</p>
  
  <ul>
  <li>char[8]
  &lt;-- outputs 8 ascii values that spell the correct string identifier</li>
  <li>dword
  &lt;--version of the data files, msw-major version, lsw-minor version (have tried reading as 1 uint32 and 2 uint16's)</li>
  <li>dword </li>
  <li>dword</li>
  <li>dword</li>
  <li>dword
  &lt;--number of window displays in program</li>
  <li>displayinfo[8]
  &lt;--contains display window params in the following structure: (not sure what data type this is)</li>
  <li>dword </li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword</li>
  <li>dword
  (end of display window params; some are specified as must be a number in [0,3] and they aren't coming out like that)</li>
  <li>char[16]</li>
  <li>word &lt;-- supposed to be year data was collected (2013) but coming up as 0</li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>fid = fopen('MIC1.001','rb');
  fileIdentifier = fread(fid, 8,'char');    
  dataFileMajorVersion = fread(fid,1,'uint16');
  dateFileMinorVersion = fread(fid,1,'uint16');
  numModules = fread(fid,1,'uint32');
  
  fread(fid,1,'uint32'); % value not used     
  numSwipesCollected = fread(fid,1,'uint32');
  numWindowDisplays = fread(fid,1,'uint32');
  % display info vars:
  displayType = [];
  moduleNumber = [];
  channelNumber = [];    
  beginningBar = [];
  endBar = [];
  vertExpFactor = [];
  voltageOffset =[];
  isGridEnabled = [];
  isEngineeringUnitEnabled = [];
  colorOfDisplay = [];
  multiChannelIndex = [];
  numChannelsForMultiChannelDisp = [];
  multiChannelDispStyle = [];
  
  % or does it go through loop for all 8 whether or not there are 8 displays??
  for i=1:numWindowDisplays 
    displayType = [fread(fid,1,'uint32'); displayType];
    moduleNumber = [fread(fid,1,'uint32'); moduleNumber];
    channelNumber = [fread(fid,1,'uint32'); channelNumber];
    beginningBar = [fread(fid,1,'uint32'); beginningBar];
    endBar = [fread(fid,1,'uint32'); endBar];
    vertExpFactor = [fread(fid,1,'uint32'); vertExpFactor]; 
    voltageOffset =[fread(fid,1,'uint32'); voltageOffset];
    isGridEnabled = [fread(fid,1,'uint32'); isGridEnabled];
    isEngineeringUnitEnabled = [fread(fid,1,'uint32'); isEngineeringUnitEnabled];
    colorOfDisplay = [fread(fid,1,'uint32'); colorOfDisplay];
    multiChannelIndex = [fread(fid,1,'uint32'); multiChannelIndex];
    numChannelsForMultiChannelDisp = [fread(fid,1,'uint32'); numChannelsForMultiChannelDisp];
    multiChannelDispStyle = [fread(fid,1,'uint32'); multiChannelDispStyle];
  end    
  fread(fid,1,'uint32'); % value only used internally
  fread(fid,16,'char'); % unused parameter for future use
  yearOfDataCollection = fread(fid,1,'uint16'); 
  </code></pre>