Main Content

readall

Read all data in datastore

Description

data = readall(ds) returns all the data in the datastore specified by ds. If all the data in the datastore does not fit in memory, then readall returns an error.

example

data = readall(ds,UseParallel=tf) reads the data in parallel if tf is true (requires Parallel Computing Toolbox™).

example

Examples

collapse all

Create an ImageDatastore object containing four images.

imds = imageDatastore({'street1.jpg','street2.jpg','peppers.png','corn.tif'});

Read all the data in the datastore.

T = readall(imds);

Examine the output.

imout = imtile(T);
imshow(imout)

Figure contains an axes object. The hidden axes object contains an object of type image.

Create a datastore from the sample file airlinesmall_subset.csv, which contains tabular data.

ds = tabularTextDatastore("airlinesmall_subset.csv",TreatAsMissing="NA");

Specify the variables of interest using the SelectedVariableNames property.

ds.SelectedVariableNames = ["DepTime","ArrTime","ActualElapsedTime"];

Read all the data in the datastore in parallel.

T = readall(ds,UseParallel=true);

readall returns all the data in a table.

View information about the table. Only the selected variables are included in the output.

T.Properties
ans = 
  TableProperties with properties:

             Description: ''
                UserData: []
          DimensionNames: {'Row'  'Variables'}
           VariableNames: {'DepTime'  'ArrTime'  'ActualElapsedTime'}
           VariableTypes: ["double"    "double"    "double"]
    VariableDescriptions: {}
           VariableUnits: {}
      VariableContinuity: []
                RowNames: {}
        CustomProperties: No custom properties are set.
      Use addprop and rmprop to modify CustomProperties.

Create a datastore that maintains parity between the pair of images of the underlying datastores. For instance, create two separate image datastores, and then create a combined datastore representing the two underlying datastores.

Create an image datastore imds1 representing a collection of three images.

imds1 = imageDatastore({'street1.jpg','street2.jpg','peppers.png'}); 

Create a second datastore imds2 by transforming the images of imds1 to grayscale and then downsizing the images.

imds2 = transform(imds1,@(x) imresize(im2gray(x),0.5));

Create a combined datastore from imds1 and imds2.

imdsCombined = combine(imds1,imds2);

Read all of the data from the combined datastore. The output is a 3-by-2 cell array. The two columns represent all of the read data from the two underlying datastores imds1 and imds2, respectively.

dataOut = readall(imdsCombined)
dataOut=3×2 cell array
    {480x640x3 uint8}    {240x320 uint8}
    {480x640x3 uint8}    {240x320 uint8}
    {384x512x3 uint8}    {192x256 uint8}

Input Arguments

collapse all

Input datastore. You can use these datastores as input to the readall method.

Read in parallel, specified as true or false. If you specify true, readall reads all data from the datastore in parallel (requires Parallel Computing Toolbox). Parallel reading may result in improved performance when reading data, especially with remote data.

  • Datastore processing can be improved with the UseParallel property and the Parallel Computing Toolbox. readall reads supported datastores faster on the local machine by using low overhead computing environments such as thread-based parallel pools. For more information on thread-based parallel pools see parpool (Parallel Computing Toolbox).

  • As a result of MATLAB's built-in multithreading, certain datastores (for example, imageDatastore) perform faster on the local machine when not using parallelism based on MATLAB workers. For more information see MATLAB Multicore.

Example: readall(ds,UseParallel=true)

Output Arguments

collapse all

All data in the datastore, returned as a table or a cell array depending on the type of ds.

Type of DatastoreData type of dataDescription
TabularTextDatastore and SpreadsheetDatastoreTableThe SelectedVariableNames property determines the table variables.
ImageDatastoreCell array Each element in the cell array contains the image data for one image. The readall function supports all image types supported by the imread function. For more information on the supported image types, see imread.
KeyValueDatastoreTableThe table variable names are Key and Value.
FileDatastoreCell arrayEach element in the cell array contains the data read from one file using the custom read function specified by the ReadFcn property.
TransformedDatastoreDependent on input datastore and transform functionTransformedDatastore reads from the underlying datastore, calls the associated transform function, and vertically concatenates the data. If your datastore is nonuniform and you want underlying datastore data to be vertically concatenated, wrap your transform function output in braces.
CombinedDatastoreDependent on input datastore

If an underlying datastore is uniform, then its data is combined (horizontal concatenation) with the data of all other datastores without modification.

If an underlying datastore is nonuniform, then its data is wrapped in a cell before being combined (horizontal concatenation) with the data of all other datastores.

SequentialDatastoreDependent on input datastore

The output is the result of the vertical concatenation of all data from underlying datastores.

If all underlying datastores are empty, output is the empty type based on the first underlying datastore. If there are no underlying datastores, output is an empty double.

If an underlying datastore is uniform, then its data is combined with the data of all other datastores without modification.

If an underlying datastore is nonuniform, then its data is wrapped in a cell before being combined with the data of all other datastores.

Extended Capabilities

Version History

Introduced in R2014b

See Also

| |