Write and Read Character Data
dsp.BinaryFileReader System objects 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
Write the Character Data
Cast a character into
uint8 using the
cast function. Write the cast data to the data file
data = 'binary_file'; castData = cast(data,'uint8'); writer = dsp.BinaryFileWriter('myFile.dat'); writer(castData);
Release the writer so that the reader can access the data.
Configure the reader to read the cast data as
reader = dsp.BinaryFileReader('myFile.dat',... 'DataType','uint8',... 'SamplesPerFrame',11); readerData = reader(); charData = char(readerData);
Verify that the writer data is the same as the reader data. By default, the reader returns the data in a column-major format.
ans = logical 1