How to skip header consit of integer words
9 ビュー (過去 30 日間)
古いコメントを表示
The file I am trying to read has following description: The files were written in IEEE binary (big-endian). Each file contains three records described as follows:
rec 1: date and version number (8 4-byte integer words)
rec 2: gridded sst values in degC (360*180 4-byte real words)
rec 3: gridded ice concentration (360*180 1-byte integer words)
How can I read rec 2 and rec 3 data without worrying about the rec 1? I've tried using fseek but it's not working. For rec 2 I am using something like: sst=fread(fid2,[360,200],'real*4',1,'ieee-be'); but I am getting all crazy nos which doesn't make any sense.
Thanks.
0 件のコメント
採用された回答
dpb
2014 年 7 月 9 日
fid=fopen('file','r','ieee-be');
fseek(fid,8*4);
temp=fread(fid,[360,180],'real*4','ieee-be').'; % no skip and fix size and orientation
ice=fread(fid,[360,180],'real*4','ieee-be').';
fid=fclose(fid);
Certainly after the first value skipping a byte will really screw everything after up until get thru the cycle of four bytes at which you should get one correct value again. Also remember Matlab fills the array in column-major order.
If after the above, data don't look like real floating point values, I'd suspect native format as the option.
3 件のコメント
dpb
2014 年 7 月 9 日
編集済み: dpb
2014 年 7 月 9 日
OOOPS! My bad; I cut 'n pasted and forgot to change the size. It says "1-byte integer" so I'd probably choose 'int8' or 'integer*1' but one presumes a concentration won't be negative so IA's 'uint8' will have the same effect.
Sorry for the oversight...
ADDENDUM
Also, just for the record note that memmapfile is useful for decoding such things, particularly if there are multiple sets of data within the file (C structs, iow).
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!