LowEndian到BigEndian - Matlab

时间:2015-09-17 12:18:51

标签: matlab

我用这种方式读取字节:

filename = 'random_path';
f=fopen(filename,'rb');%f=fopen(filename,'rb');
if f<3, error('Impossivel abrir %s',filename); end
samples= fread(f,202*4096,'int16')'; 

此文件是在LowEndian中编写的。现在我想将它传递给BigEndian。我试试这个,没有成功。

read= fopen('big_endian','wb');
fwrite(read,int16(swapbytes(samples)),'int16');
fclose(read)

1 个答案:

答案 0 :(得分:0)

你应该尝试:

%read the data

fid  = fopen('random_path','r','ieee-le'); %ieee-le = Low endian
data = fread(fid,inf,'int16');

%write the data

fid  = fopen('random_path_le','w','ieee-be'); %ieee-be = Big endian
fwrite(fid,data,'int16');