So I'm trying to work with some data files that contain a text header followed by binary data, 16 bits signed integers with the least significant byte first.
I can't seem to open the binary data correctly. The text header is of variable length. I've tried the following, but my problem is that the data is not actually stored as binary, but is already a number, but not correctly. The header is of variable length so I can't tell it to read after so many characters without first opening the file.
fileName = 'PATH/TO/FILE/FILE_NAME.DAT';
dataFile = fopen(fileName);
header = '';
i = 1;
%dataContents = fileread(fileName);
dataContents = fread(dataFile);
while i < 115
char = dataContents(i);
header = [header char];
if char == '}'
break
end
i = i + 1;
end
header = header(2:end-1);
headerSplit = strsplit(header,',');
fileSize = str2double(headerSplit(17));
binaryData = dataContents(i:end);
data = [];
j = 1;
num = binaryData(1:50)
while j < fileSize
data = [data, bin2dec(num2str(binaryData(j:j+1)))];
j = j + 2;
end
length(data)
Any help would be great. I'm new to matlab so I'm probably missing something simple.