Reading in binary file leads to empty matrix
显示 更早的评论
I have a binary file ('test') together with a header file ('test.hdr') which I am trying to import into matlab. I can read out the information out of the header file, however I am struggling to read in the binary file. Here you can download the two files I am trying to import.
This is my code so far:
% read in header file
[fid message]=fopen('test.hdr','rt');
if(~isempty(message))
error(message);
return;
end
while(~feof(fid)) % Repeat the following command sequence until EOF is reached
textline=fgetl(fid);
[nameAndValue] = regexp(textline,'=','split');
fieldName = strtrim(nameAndValue{1});
value = strtrim(nameAndValue{2});
if(~isempty(str2num(value)))
value = str2num(value);
else
value = strtok(value,'''');
end
header.(fieldName) = value;
end
fclose(fid);
% read in binary
[fid message]=fopen('test','wb','ieee-be');
if(~isempty(message))
error(message);
return;
end
How could I read in the data, the header contains informatio about the data type and the dimensions of the matrix. When trying to read in data like this I get an empty matrix A.
A=fread(fid);
How could I read in this data with using the header information? The binary file is exported from ENVI and in big-endian byte order.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!