C g*_*ics 2 file-io matlab binaryfiles
在matlab中,我想从一个结构化的,相当大的文件(大小:18 + 2048*2048字节)中读取,其中18个拳头字节被分配给头部,其余的是像素图像强度.这里关注的是速度.正如您在下面的代码中看到的,对文件的多次访问大大降低了性能.您能否建议以更快的方式从文件中读取这些内容?例如,使用"fread"函数读取缓冲区中的整个内容.
fid = fopen(fileName, 'r', 'b'); % 'r' readonly and 'b' big endian
a= fread(fid,1,'uint16');
b1= fread(fid,1,'uint32');
b2= fread(fid,1,'uint32');
c1= fread(fid,1,'uint32');
c2= fread(fid,1,'uint32');
img=zeros (...
for i= (b1 + 1) : (b2 + 1)
for j= (c1 + 1) : (c2 + 1)
img(i, j) = fread(fid,1,'uint16');
end
end
Run Code Online (Sandbox Code Playgroud)