%% Read Data Using Custom Datastore And Process in Parallel Pool
% Use custom datastore to preview and read your proprietary data into MATLAB for parallel processing.
% This example uses a simple data set to illustrate a workflow using your custom datastore. The data set is a collection of 15 binary (.bin) files where each file contains a column (1 variable) and 10000  rows (records) of unsigned integers.

dir('*.bin')

% Create a datastore object using the MyDatastorePar function. For implementation details of MyDatastorePar, see the example Build Datastore with Parallel Processing Support.

folder = fullfile('*.bin'); 
ds = MyDatastorePar(folder); 

% Preview the data from the datastore.

preview(ds)

% Identify the number of partitions for your datastore. If you have Parallel Computing Toolbox (PCT), then you can use n = numpartitions(ds,myPool), where myPool is gcp or parpool.

n = numpartitions(ds); 

% Partition the datastore into n parts and n workers in a parallel pool.

parfor ii = 1:n
    subds = partition(ds,n,ii);
      while hasdata(subds)
        data = read(subds);
        % do something
      end
end

% Copyright 2017 The MathWorks, Inc.