フィルターのクリア

read I/Q data from binary file

32 ビュー (過去 30 日間)
abhinibesh
abhinibesh 2014 年 2 月 25 日
回答済み: Walter Roberson 2014 年 2 月 25 日
1st ques: How can I read from a binary file, byte by byte?? 2nd ques: How can I read from a binary file, 2 bytes at a time??

回答 (1 件)

Walter Roberson
Walter Roberson 2014 年 2 月 25 日
fid = fopen('YourFile.bin', 'r'); %for read
data_by_one = fread(fid, '*uint8'); %read it a byte at a time
frewind(fid); %go back to the beginning
data_by_two = fread(fid, '*uint16'); %read two bytes at a time
frewind(fid); %go back to the beginning
data_by_two_swapped = fread(fid, '*uint16', 'ieee-be'); %two bytes at a time, big-ended
fclose(fid);
The default for two-byte integers is "little-ended", where the file has PQ where in memory the value would be (256 * Q + P). Reading 'big-ended' would read bytes PQ as representing (256 * P + Q), the way that God intended ;-)

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by