MATLAB - Binary file read
Reading binary data in Matlab is easy. Just open the file and read the data like this.
fp = fopen(filename, ‘r’);
[data, count] = fread(fp, ‘uint8’);
fclose(fp);
10MB of data is an awful lot of data to display but if you only want to look at a small portion of it then the easiest way to display it as nibbles is in hexadecimal format.
printf(‘%08x\n”, data(iBeg:iEnd));
If you would rather display the data as binary then do the following
for idx = iBeg:iEnd
printf(‘%s\n’, dec2bin(data(idx,32));
end
My requirement is to read 8 consecutive nibbles as part of one 32 bit sample and store it as one record/sample. Also what is the iBeg and iEnd variables that you use in the loop?
fid = fopen('finename.bin','r');
[data count]=fread(fid,'uint32'); was what I was looking for. It reads data in as 32 bit unsigned integer which can later be converted to string using dec2bin