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
).
TransformedDatastore
is shuffleable if all underlying datastores are shuffleable.CombinedDatastore
andSequentialDatastore
are shuffleable if all underlying datastores have a subset method or are transformations/combinations of datastores that havesubset
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
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
ds
— Input datastore
datastore
Input datastore. You can use these datastores as input:
- MATLAB® datastores — Datastores created using MATLABdatastore 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 theisShuffleable
function. See Develop Custom Datastore for more information.
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:
- In a thread-based environment, you can use
isShuffleable
only with the following datastores:ImageDatastore
objectsCombinedDatastore
,SequentialDatastore
, orTransformedDatastore
objects you create fromImageDatastore
objects by usingcombine
ortransform
You can useisShuffleable
with other datastores if you have Parallel Computing Toolbox™. To do so, run the function using a process-backed parallel pool instead of usingbackgroundPool
orThreadPool
(use eitherProcessPool
orClusterPool
).
For more information, see Run MATLAB Functions in Thread-Based Environment.
Version History
Introduced in R2020a