%% Change the Endianness of the Data in Simulink
% By default, the <docid:dsp_ref#bvevpo_-1 Binary File Reader> block uses 
% the endianness of the host machine. To change the endianness, such as 
% when the host machine that writes the data does not have the same 
% endianness as the host machine that reads the data, use the 
% |swapbytes| function.

%%
% Write a numeric array in big endian format into the file |bigEndian.dat|. 
% Read the data using the |Binary File Reader| block. The reader reads the 
% data in little endian format.
fid = fopen('bigEndian.dat','w','b');
fwrite(fid,[1 2 3 4 5 6 7 8],'double');
fclose(fid);

%%
% Open and simulate the model.
model = 'changeEndian';
open_system(model)
sim(model)

%%
% Display the data variable, _x_.
display(x)

%%
% The array |x| does not match the original data. Change the endianness of |x| using 
% the |swapbytes| function.
y = swapbytes(x);
display(y)

%%
% That array |y| matches the original data.

%% 
% Copyright 2012 The MathWorks, Inc.