%example:
% file = 'E:\SARImages\TanDEM_Shenzhen\TDM1_SAR__COS_BIST_SM_Q_DRA_20151101T102545_20151101T102548\2015_11_01_roi\master\s11.bin';
% w = 128; h = 128;
% calss:数据类型,complex,float,double
function [output,mat_output] = readBin(class,filepath,w,h,byteOrder)
if ~exist(byteOrder)
byteOrder = 'n'; %二进制数据的读取顺序
end
switch class
case 'complex'
fid = fopen(filepath,'r');
%构建二进制向量
output = zeros(1,w*h);
%读取二进制流
temp = fread(fid,2*w*h,'float',byteOrder);
% 重拍实部和虚部
output = temp(1:2:end) + temp(2:2:end)*1j;
case 'float'
% 创建句柄
fid = fopen(filepath,'r');
% 读取所有文件
output = fread(fid,w*h,'float',byteOrder);
case 'double'
% 创建句柄
fid = fopen(filepath,'r');
% 读取所有文件
output = fread(fid,w*h,'double',byteOrder);
end
fclose(fid);
% 恢复矩阵格式
mat_output = reshape(output,w,h);
imshow(mat_output',[]); %与envi的按列成像一致(matlab将二进制流按行成像)
h = colorbar;
set(get(h,'Title'),'string','单位:m');