%% Read Complex Data
% Read complex data from a binary file using the dsp.BinaryFileReader object.
% Write a sequence of numbers to a binary file named myfile.dat. There is no header. The data is a 2-by-4 matrix of double-precision values.  fwrite writes the data in a column-major format. That is, the 2-by-4 matrix [1 2 3 4; 9 10 11 12] is written as [1 9 2 10 3 11 4 12] in the binary file.

fid = fopen('myfile.dat','w');
fwrite(fid,[1 2 3 4; 9 10 11 12],'double');
fclose(fid);

%
% Specify the data to be complex using the IsDataComplex property. The object reads the data as interleaved real and imaginary components. The SamplesPerFrame and NumChannel properties specify the number of rows and columns of the output data. The header structure is specified as empty.

reader = dsp.BinaryFileReader('myfile.dat','SamplesPerFrame',2,...
    'NumChannels',2,'IsDataComplex',true);
s = struct([]);
reader.HeaderStructure = s;
data = reader();
display(data);
release(reader);

%
% Alternatively, if you do not specify the data as complex, the reader reads the data as a SamplesPerFrame-by- NumChannel matrix of real values.

reader.IsDataComplex = false;
data = reader();
display(data);
release(reader);

% Copyright 2012 The MathWorks, Inc.