isSubsettable - Determine whether datastore is subsettable - MATLAB (original) (raw)
Determine whether datastore is subsettable
Since R2022b
Syntax
Description
tf = isSubsettable([ds](#mw%5Fb0ade1fd-6df2-4f6d-95bd-cd80b75e0299))
returns logical1
(true
) if the datastore is able to be subsetted. If the datastore is not subsettable, the result is logical 0
(false
). Datastores containing underlying datastores, such asTransformedDatastore
, CombinedDatastore
, andSequentialDatastore
, are subsettable only when all underlying datastores are subsettable.
Examples
Test If Datastore Is Subsettable
Create an image datastore for the image files in a sample folder. Then, write an if/else
statement that subsets the datastore only if it is subsettable.
folders = fullfile(matlabroot,"toolbox","matlab",["demos",fullfile("matlab_images",["png","tiff"])]); exts = [".jpg",".png",".tif"]; imds = imageDatastore(folders,"LabelSource","foldernames","FileExtensions",exts);
Write an if/else
statement that subsets the datastore only if it is subsettable.
if isSubsettable(imds) newds = subset(imds,2); disp("Subset successful.") else disp("Datastore is not subsettable.") end
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 is a subclass of
matlab.io.Datastore
supports theisSubsettable
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
isSubsettable
only with the following datastores:ImageDatastore
objectsCombinedDatastore
,SequentialDatastore
, orTransformedDatastore
objects you create fromImageDatastore
objects by usingcombine
ortransform
You can useisSubsettable
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 R2022b