Reading in binary file leads to empty matrix
Show older comments
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.
Accepted Answer
More Answers (0)
Categories
Find more on Large Files and Big Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!