Main Content

isShuffleable

Determine whether datastore is shuffleable

Description

example

tf = isShuffleable(ds)returns logical1(true) if the datastoredsis shuffleable. Otherwise, the result is logical0(false).

  • TransformedDatastoreis shuffleable if all underlying datastores are shuffleable.

  • CombinedDatastoreis shuffleable if all underlying datastores have asubsetmethod or are transformations/combinations of datastores that havesubsetmethods..

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

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

Examples

collapse all

Create anImageDatastore, and then write an如果/elsestatement that shuffles the datastore only if it is shuffleable.

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

Now create aCombinedDatastoreobject comprised of two copies ofimds. Use the same如果/elsetest to shuffle the datastore.

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

In this case, the combined datastorecdsis shuffleable because the underlyingImageDatastoreobjects havesubsetmethods.

Create anotherCombinedDatastoreobject, but this time construct it out ofTabularTextDatastoreobjects. In this case the combined datastore is not shuffleable because the underlyingTabularTextDatastoreobjects do not havesubsetmethods.

ttds = tabularTextDatastore('outages.csv'); cds = combine(ttds,ttds);ifisShuffleable(cds) newds = shuffle(cds); disp('Shuffling successful.')elsedisp('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 MATLABdatastorefunctions. For example, create a datastore for a collection of images usingImageDatastore. For a complete list of datastores, seeSelect Datastore for File Format or Application.

  • Combined and transformed datastores — Datastores created using thecombineandtransformfunctions.

  • Custom datastores — Datastores created using the custom datastore framework. Any datastore that subclasses frommatlab.io.Datastoresupports theisShuffleablefunction. SeeDevelop Custom Datastorefor more information.

Extended Capabilities

Version History

Introduced in R2020a