isShuffleable - Determine whether datastore is shuffleable - MATLAB (original) (raw)

Main Content

Determine whether datastore is shuffleable

Since R2020a

Syntax

Description

tf = isShuffleable([ds](#mw%5Fefe5ff72-6758-464d-b922-e56ccd851e68)) returns logical1 (true) if the datastore ds is shuffleable. Otherwise, the result is logical 0 (false).

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.

example

Examples

collapse all

Test Shuffleability of Datastores

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

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

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

ds — Input datastore

datastore

Input datastore. You can use these datastores as input:

Extended Capabilities

Thread-Based Environment

Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Usage notes and limitations:

For more information, see Run MATLAB Functions in Thread-Based Environment.

Version History

Introduced in R2020a