%% Write and Read Character Data from Binary Files in Simulink
% The <docid:dsp_ref#bve9jr5-1 Binary File Writer> and <docid:dsp_ref#bvevpo_-1 Binary
% File Reader> blocks do not support writing and reading characters. As a 
% workaround, cast character data to one of the built-in data types and 
% write the integer data. After the reader reads the data, convert the data 
% to a character using the |char| function.

%% Write the Character Data
% Cast the character data, |'binary_file'| into |uint8| using the |cast|
% function. 
data = 'binary_file';

%%
% Write the cast data to the data file |myCharFile.dat|.
writeModel = 'writeCharData';
open_system(writeModel)
sim(writeModel)

%% Read the |uint8| Data
% Specify the reader to read the cast data as |uint8| data.
readModel = 'readCharData';
open_system(readModel)
sim(readModel);

%%
charData = char(readerData);

%%
% Verify that the writer data is same as the reader data. By default, the 
% reader returns the data in a column-major format.
strcmp(data,charData.')

%% 
% Copyright 2012 The MathWorks, Inc.