Main Content

isShuffleable

Determine whether datastore is shuffleable

Since R2020a

Description

example

tf = isShuffleable(ds) returns logical 1 (true) if the datastore ds is shuffleable. Otherwise, the result is logical 0 (false).

  • TransformedDatastore is shuffleable if all underlying datastores are shuffleable.

  • CombinedDatastore and SequentialDatastore are shuffleable if all underlying datastores have a subset method or are transformations/combinations of datastores that have subset methods..

  • Custom datastore classes are shuffleable if they subclass from matlab.io.datastore.Shuffleable.

You can use the shuffle function on shuffleable datastores to randomize the ordering of files, while preserving the row associations of files in different datastores.

Examples

collapse all

Create an ImageDatastore, and then write an if/else statement that shuffles the datastore only if it is shuffleable.

imageFiles = {'street1.jpg','street2.jpg','peppers.png','corn.tif'};
imds = imageDatastore(imageFiles);
if isShuffleable(imds)
    newds = shuffle(imds);
    disp('Shuffling successful.')
else
    disp('Datastore is not shuffleable.')
end
Shuffling successful.

Now create a CombinedDatastore object comprised of two copies of imds. Use the same if/else test to shuffle the datastore.

cds = combine(imds,imds);
if isShuffleable(cds)
    newds = shuffle(cds);
    disp('Shuffling successful.')
else
    disp('Datastore is not shuffleable.')
end
Shuffling successful.

In this case, the combined datastore cds is shuffleable because the underlying ImageDatastore objects have subset methods.

Create another CombinedDatastore object, but this time construct it out of TabularTextDatastore objects. In this case the combined datastore is not shuffleable because the underlying TabularTextDatastore objects do not have subset methods.

ttds = tabularTextDatastore('outages.csv');
cds = combine(ttds,ttds);
if isShuffleable(cds)
    newds = shuffle(cds);
    disp('Shuffling successful.')
else
    disp('Datastore is not shuffleable.')
end
Datastore is not shuffleable.

Input Arguments

collapse all

Input datastore. You can use these datastores as input:

  • MATLAB® datastores — Datastores created using MATLAB datastore functions. For example, create a datastore for a collection of images using ImageDatastore. For a complete list of datastores, see Select Datastore for File Format or Application.

  • Combined, sequential, and transformed datastores — Datastores created using the combine and transform functions.

  • Custom datastores — Datastores created using the custom datastore framework. Any datastore that subclasses from matlab.io.Datastore supports the isShuffleable function. See Develop Custom Datastore for more information.

Extended Capabilities

Version History

Introduced in R2020a