Main Content

isSubsettable

Determine whether datastore is subsettable

Since R2022b

Description

tf = isSubsettable(ds) returns logical 1 (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 as TransformedDatastore, CombinedDatastore, and SequentialDatastore, are subsettable only when all underlying datastores are subsettable.

example

Examples

collapse all

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
Subset successful.

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 is a subclass of matlab.io.Datastore supports the isSubsettable function. See Develop Custom Datastore for more information.

Extended Capabilities

Version History

Introduced in R2022b