微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 微波和射频技术 > 电磁仿真讨论 > MATLAB - Binary file read

MATLAB - Binary file read

时间:03-30 整理:3721RD 点击:
I have a binary file around 10MB which is created by continuously logging 32 bit data samples for a fixed period of time. What is the best way to read this file in MATLAB and make it appear as a column vector each with 32 bits preferably displayed as 8 nibbles.

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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top